开发者

Creating a line graph with powerplot in iPhone

i'm using powerplot to create a dynamic graph in iphone. while going through http://www.field-theory.org/articles/powerplot/example.html i successfully create a graph, but i do not know how do i remove the default dec value inside the graph.

Creating a line graph with powerplot in iPhone

i will like to create something like this below, that i conceptualise from mockapps.

float sourceData[7] = {33, 17, 24, 11, 11, 4, 10};
    self.allData = [WSData dataWithValues:[WSData arrayWithFloat:sourceData withLen:7]];
self.allData = [self.allData indexedData];

WSChart *tmp;
tmp = [WSChart linePlotWithFrame:[aView frame]
                                 withData:self.allData
                                 withStyle:kChartLineFilled
                                 withAxisStyle:kCSGrid
                                 withColorScheme:kColorGray
                                 withLabelX:@"Days"
                                 withLabelY:@"Drinks"];
             [aView removeAllPlots];
             [aView addPlotsFromChart:tmp];

[aView scaleAllAxisYD:NARangeMake(-10, 45)];
[aView setAllAxisLocationYD:0];
[aView setAllAxisLocationXD:-0.5];  


WSPlotAxis *axis = [aView getPlotAxis];

[[axis ticksX] setTicksStyle:kTicksLabels];
[[axis ticksY] setTicksStyle:kTicksLabels];
[[axis ticksY] ticksWithNumbers:[NSArray arrayWithObjects:
                                 [NSNumber numberWithFloat:0],
                                 [NSNumber numberWithFloat:10],
                                 [NSNumber numberWithFloat:20],
                                 [NSNumber n开发者_高级运维umberWithFloat:20],
                                 nil]
                     withLabels:[NSArray arrayWithObjects:@"",
                                 @"10%", @"20%", @"30%", nil]];

[axis.ticksX setTickLabelsWithStrings:[NSArray arrayWithObjects:@"Mon", @"Tue", @"Wed",
                                       @"Thur", @"Fri", @"Sat", @"Sun", nil]];



[aView setNeedsDisplay];

any comments are appreciated thanks :)

Creating a line graph with powerplot in iPhone


The linePlotWithFrame:... method of WSChart generates two separate instances of WSPlotAxis on the plot-stack. The first instance is for the grid only, the second for the axis ticks and labels.

The method WSPlotAxis *axis=[aView getPlotAxis] will return the first view of type WSPlotAxis which does not have any tick labels initially. If you want to manually change the existing axis ticks and labels, you need to get the second instance by using

WSPlotAxis *axis = (WSPlotAxis *)[self.chart plotAtIndex:2].view;

instead of WSPlotAxis *axis=[aView getPlotAxis];.

Then it will work as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜