PowerPlotPercolation logo

Scientific plot

This scientific data plot shows different ways to configure plots and data. It compares factory methods to manual configuration. While the factory methods provide a variety of viewing options, they also abstract the powerful MVC-design that allows charts to be highly configurable. This example compares both the factory-methods for charts and manual configuration. We find how individual setting of properties can fine-tune the appearance of a chart.

This page describes the class “ScientificLines” in the PowerPlot demo app.

Scientific data 1

First, this is how a plot is created using a factory method (this is what the second button at the bottom of the demo app shows):

    // Autoconfigure the plot choice1.
    _choice[1] = [WSChart linePlotWithFrame:[self.chart frame]
                                       data:testD
                                      style:kChartLineGradient
                                  axisStyle:kCSGrid
                                colorScheme:kColorDark
                                     labelX:NSLocalizedString(@"Crystal orientation", @"")
                                     labelY:NSLocalizedString(@"Energy output", @"")];
    [_choice[1] retain];
    [_choice[1] setAllAxisLocationXD:1.328];
    [_choice[1] setAllAxisLocationYD:-0.1];

Except for the color scheme, the third choice is identical to the above one.

Now let's see how to create and configure this plot manually without any factory method (the default, shown when then first button in the demo app is pressed):

    // Our test data.
    WSData *testD = [DemoData scientificData];

    // Manually configure the plot choice0.
    // This demonstrates how widely a data plot can be configured.
    _choice[0] = [[WSChart alloc] initWithFrame:[self.chart frame]];
    [_choice[0] resetChart];
    WSPlotAxis *axis = [[WSPlotAxis alloc] initWithFrame:[self.chart frame]];
    WSPlotData *lines = [[WSPlotData alloc] initWithFrame:[self.chart frame]];
    axis.axisX.axisStyle = kAxisArrowFilledHead;
    axis.axisY.axisStyle = kAxisArrowFilledHead;
    axis.axisX.labelStyle = kLabelInside;
    axis.axisX.axisLabel = NSLocalizedString(@"Crystal orientation", @"");
    axis.axisY.labelStyle = kLabelInside;
    axis.axisY.axisLabel = NSLocalizedString(@"Energy output", @"");
    axis.axisColor = [UIColor blackColor];
    axis.ticksX.ticksDir = kTDirectionInOut;
    axis.ticksY.ticksDir = kTDirectionInOut;
    axis.gridColor = [UIColor grayColor];
    axis.gridStrokeWidth = 1.0;
    axis.axisX.gridStyle = kGridDotted;
    axis.axisY.gridStyle = kGridDotted;
    lines.propDefault.symbolSize = 15.0;
    lines.propDefault.symbolStyle = kSymbolSquare;
    lines.propDefault.symbolColor = [UIColor greenColor];
    lines.propDefault.errorStyle = kErrorXYCapped;
    lines.lineStyle = kLineRegular;
    lines.dashStyle = kDashingDashed;
    lines.intStyle = kInterpolationStraight;
    lines.shadowEnabled = YES;
    lines.shadowScale = 5.0;
    lines.shadowColor = [UIColor blackColor];
    WSPlotController *axisController = [[WSPlotController alloc] init];
    WSPlotController *linesController = [[WSPlotController alloc] init];
    [axisController setView:axis];
    [linesController setView:lines];
    [axisController setDataD:testD];
    [linesController setDataD:testD];
    [_choice[0] addPlot:axisController];
    [_choice[0] addPlot:linesController];
    [_choice[0] autoscaleAllAxisX];
    [_choice[0] autoscaleAllAxisY];
    [axis autoTicksXD];
    [axis autoTicksYD];
    [axis setTickLabelsX];
    [axis setTickLabelsY];
    [[axis ticksX] setTicksStyle:kTicksLabelsSlanted];
    [[axis ticksY] setTicksStyle:kTicksLabelsSlanted];
    [_choice[0] setAllAxisLocationXD:1.328];
    [_choice[0] setAllAxisLocationYD:-0.1];
    [axis release];
    [lines release];
    [axisController release];
    [linesController release];

This code shows off what properties can be adjusted to fine-tune a plot appearance. However, typically an app developer using PowerPlot does not need to use all of these options, she can just fix what she is interested in after the factory method has been used.