GeekWorkCode / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Plot points range are not expanding #147

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Let say data plot values are
X: 12 Jan,2010   Y: 30
X: 15 Feb,2010   Y: 23
X: 03 Mar,2010   Y: 26 (they are just the raw data to have an idea about
the input values)

The allowInteraction property has been set True
The x.labellingpolicy=fixedInterval
The x.preferredNumberOfMajorTicks=10 
The x.majorIntervalLength=SevenDay //60*60*24*7

Please refer to the image A
All the data points are plotted at a correct place but the xAxis values are
too nearby. The space between them is not appropriate.
Now, please refer to the image B
The x.majorIntervalLength=OneDay //60*60*24
Well all the data points are still plotted at a correct place but the xAxis
values are too nearby. 

I had tried to change the view bounds, but still no results

What is the expected output? What do you see instead?
The space between them should be appropriate i.e. every xAxis values should
be visible with appropriate gap between them

Please guide me 
Regards Zahur

Original issue reported on code.google.com by zghotlawala@gmail.com on 25 May 2010 at 12:23

Attachments:

GoogleCodeExporter commented 8 years ago
You need to set the interval length to 1 day given in seconds = 60*60*24. 
Are you setting it as a NSDecimal?

Something like this

    x.majorIntervalLength = CPDecimalFromDouble(60*60*24.0);

Original comment by drewmcco...@mac.com on 25 May 2010 at 1:48

GoogleCodeExporter commented 8 years ago
Sir, please refer the below code.

-(void)reloadGraph{
    // Create graph from theme
    graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
    CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme];
    [graph applyTheme:theme];
    chartView =[[CPLayerHostingView alloc] initWithFrame: graphView.bounds];

    [graphView addSubview:chartView];

    chartView.hostedLayer = graph;

    graph.paddingLeft = 50.0;
    graph.paddingTop = 20.0;
    graph.paddingRight = 20.0;
    graph.paddingBottom = 30.0;

    // Create a white plot area
    boundLinePlot= [[[CPScatterPlot alloc] init] autorelease];
    boundLinePlot.identifier = @"White Plot";
    boundLinePlot.dataLineStyle.miterLimit = 0.0f;
    boundLinePlot.dataLineStyle.lineWidth = 2.0f;
    boundLinePlot.dataLineStyle.lineColor = [CPColor whiteColor];
    boundLinePlot.dataSource = self;
    [graph addPlot:boundLinePlot];

     CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
         plotSpace.allowsUserInteraction = YES;

         graph.plotAreaFrame.masksToBorder = NO;

// Grid line styles
    CPLineStyle *majorGridLineStyle = [CPLineStyle lineStyle];
    majorGridLineStyle.lineWidth = 0.75;
    majorGridLineStyle.lineColor = [[CPColor colorWithGenericGray:0.2]
colorWithAlphaComponent:0.75];

    CPLineStyle *minorGridLineStyle = [CPLineStyle lineStyle];
    minorGridLineStyle.lineWidth = 0.25;
    minorGridLineStyle.lineColor = [[CPColor whiteColor]
colorWithAlphaComponent:0.1];    

    CPLineStyle *redLineStyle = [CPLineStyle lineStyle];
    redLineStyle.lineWidth = 10.0;
    redLineStyle.lineColor = [[CPColor redColor] colorWithAlphaComponent:0.5];
     redLineStyle.lineCap=kCGLineCapRound; 
    // Text styles
    CPTextStyle *axisTitleTextStyle = [CPTextStyle textStyle];
//  axisTitleTextStyle.fontName = @"Helvetica Bold";
    //axisTitleTextStyle.fontSize = 14.0;
    axisTitleTextStyle.color=[CPColor whiteColor];

    // Add plot symbols
    CPLineStyle *symbolLineStyle = [CPLineStyle lineStyle];
    symbolLineStyle.lineColor = [CPColor blackColor];
    CPPlotSymbol *plotSymbol = [CPPlotSymbol ellipsePlotSymbol];
    plotSymbol.fill = [CPFill fillWithColor:[CPColor whiteColor]];
    plotSymbol.lineStyle = symbolLineStyle;
    plotSymbol.size = CGSizeMake(5.0, 5.0);
    boundLinePlot.plotSymbol = plotSymbol;

    [xRange expandRangeByFactor:CPDecimalFromDouble(2.0f)];

    plotSpace.xRange = xRange;

    [yRange expandRangeByFactor:CPDecimalFromDouble(1.5f)];

    plotSpace.yRange = yRange;
    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
    CPXYAxis *y = axisSet.yAxis;

    y.labelingPolicy = CPAxisLabelingPolicyAutomatic;
     y.orthogonalCoordinateDecimal=CPDecimalFromDouble(startPointX);
    y.minorTicksPerInterval = 0;
     y.majorTickLength=[yClassLength intValue];

     y.preferredNumberOfMajorTicks = 7;
    y.majorGridLineStyle = majorGridLineStyle;
    y.minorGridLineStyle = minorGridLineStyle;
    y.labelOffset = 10.0;    
    y.coordinate = CPCoordinateY;
    y.plotSpace = graph.defaultPlotSpace;
    y.axisLineStyle = redLineStyle;
    y.majorTickLineStyle = redLineStyle;
    y.minorTickLineStyle = nil;
     y.visibleRange =yRange;
     CPConstraints yConstraints = {CPConstraintFixed, CPConstraintNone};
    y.isFloatingAxis = YES;
     y.constraints = yConstraints;
     y.labelTextStyle=axisTitleTextStyle;

     CPXYAxis *x=axisSet.xAxis;
    x.labelingPolicy = CPAxisLabelingPolicyFixedInterval;
     x.orthogonalCoordinateDecimal=CPDecimalFromInteger(startPointY);
    x.minorTicksPerInterval = 0;
     x.majorIntervalLength=CPDecimalFromDouble(XTimeInterval);
    x.preferredNumberOfMajorTicks = 10;
    x.labelOffset = 12.0;    
    x.coordinate = CPCoordinateX;
    x.plotSpace = graph.defaultPlotSpace;
    x.axisLineStyle = redLineStyle;
    x.majorTickLineStyle = redLineStyle;
    x.minorTickLineStyle = redLineStyle;

     CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc]
initWithDateFormatter:xDateFormatter] autorelease];
    timeFormatter.referenceDate = refDate;

     x.labelFormatter=timeFormatter;
     x.labelTextStyle=axisTitleTextStyle;
    x.visibleRange =xRange;
    CPConstraints xConstraints = {CPConstraintFixed, CPConstraintNone};
     x.isFloatingAxis = YES;
     x.constraints = xConstraints;

    // Set axes
    graph.axisSet.axes = [NSArray arrayWithObjects:y,x,nil];

      // Add plot symbols
    // Auto scale the plot space to fit the plot data
    // Extend the y range by 10% for neatness
   // [plotSpace scaleToFitPlots:[NSArray arrayWithObjects:boundLinePlot,
dataSourceLinePlot, nil]];

    [plotSpace scaleToFitPlots:[NSArray arrayWithObject:boundLinePlot]];

    // Restrict y range to a global range

    plotSpace.globalYRange = yRange;
    plotSpace.globalXRange=xRange;

} //End of Code snippet
here  XTimeInterval is double values let say (60*60*24.0) for one day.
Still the same issue. Please guide me accordingly.

Original comment by zghotlawala@gmail.com on 26 May 2010 at 7:53

GoogleCodeExporter commented 8 years ago
Sir, please guide me, am really stuck with the above issue.

Original comment by zghotlawala@gmail.com on 29 May 2010 at 5:54

GoogleCodeExporter commented 8 years ago
Did you ever solve this? You should be able to get it to look right with the 
proper combination of majorIntervalLength, plot space length, and perhaps label 
rotation so they don't overlap so much.

Try a majorIntervalLength of 14 days and labelRotation of pi/4 to start with 
and see what that looks like.

Original comment by eskr...@mac.com on 26 Jun 2010 at 1:22

GoogleCodeExporter commented 8 years ago

Original comment by drewmcco...@mac.com on 12 Jul 2010 at 7:51