Search code examples
iosobjective-ccore-plot

how to show time on x axis using core plot ios sdk


I need help I want to create z axis in CorePlot using scaler plot.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // We need a hostview, you can create one in IB (and create an outlet) or just do this:
    CPTGraphHostingView* hostView = [[CPTGraphHostingView alloc] initWithFrame:self.view.frame];
    [self.view addSubview: hostView];

    // Create a CPTGraph object and add to hostView
    CPTGraph* graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
    hostView.hostedGraph = graph;

    // Get the (default) plotspace from the graph so we can set its x/y ranges
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;

    // Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
    [plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 16 )]];
    [plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( -4 ) length:CPTDecimalFromFloat( 8 )]];

    // Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
    CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];

    // Let's keep it simple and let this class act as datasource (therefore we implemtn <CPTPlotDataSource>)
    plot.dataSource = self;

    // Finally, add the created plot to the default plot space of the CPTGraph object we created before
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
}

how to set x axis time like , 1:30 , 1:32, 1:35 as per as plot points.


Solution

  • Several of the Core Plot example apps show how to create multiple x- or y-axes. See, for example, the "Axis Demo" and the "Labeling Policy Demo" in the Plot Gallery app for multiple axes that share the same plot space. The "Plot Space Demo" shows how to create multiple plot spaces in a graph and assign different axes to each one.

    If you want to keep the default x- and y-axes and add new ones, make a mutable copy of the graph.axisSet.axes array, add your new axes the array, and assign the new axis array back to the graph.axisSet.axes property.

    Core Plot does not support 3D graphs right now, so you cannot add a true z-axis. You might be able to fake it with a scatter plot, but you'd have to do all of the 3D transform math yourself.