开发者

GraphKit framework in Cocoa

开发者 https://www.devze.com 2023-01-07 13:17 出处:网络
I try to draw an XY graph using GraphKit. Information of this framework is very limited on the internet...

I try to draw an XY graph using GraphKit.

Information of this framework is very limited on the internet...

Here's what I did:

// a xychart is predefined in header as GRChart

GRDateSet *dataset = [[GRXYDataSet alloc] initWithOwnerChart:xychart];
[xychart addDataSet:dataSet loadData:YES];
[xychart reloaddata];

also I implement delegate methods:

(double)chart:(GRChartView *)aChart xValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index 

 { return index * 10.0; }

    (double)chart:(GRChartView *)aChart yValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index 
 { return index * 10.0; }

(NSUInteger) chart:(GRChartView *)aChart  numberOfElementsForDataSet:(GFDataSet*)aDa开发者_如何学CtaSet {
   return 10;
}

however, it only draws the axes but no data points at all...

what did I miss here?

thanks!


I got it. This framework only stores data points and draws axes according to the data points. (It automatically calculates the bounds of each axes and zoom into a suitable plot area.)

However, no drawing method is rooted. To get an immediate graph, I have to use GRAreaDataSet, which is a subclass of GRXYDataSet. Then it will draw an area chart.

I also tried out core-plot. But it's more difficult to use to me. I have to calculate the bounds myself; and padding the graph to show the label values of axes. Also, it's not so beautiful if I don't customize the symbols and lines. However, the default GraphKit charting is nice-looking enough. Though it doesn't have a document...

I'll try to write a tutorial of it when I try out everything in it :)

0

精彩评论

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

关注公众号