How to draw a histogram chart in cocoa
As per My 开发者_JS百科requirements i need to generate a histogram chart using cocoa framework and objective c.
If any one knows the solution please let me know ASAP.
Thanks, Ravi
You could use Core Plot. It doesn't support histograms directly, but if you calculate the bins and counts yourself, a bar plot is pretty easy to set up. The framework handles drawing everything including the axes and labels. It works on Mac, iPhone, and iPad.
Depending on your needs you can use a custom UIView subclass and perform the drawing by hand (overwrite drawRect:) or add UIViews for every bar (making nice animations possible with few code, but will not be efficient if many bars are needed).
You can easily write your own CALayer
using CoreAnimation.
You will just need some basic CALayers
with their colors, borders and shadows to draw the bars and some CATextLayers
to draw the text on the axis or below bars.
With some basic CA knowledge it will be easy and allow you to easily customize the graph with animations or effects..
I know this question is pretty old but i found a link that gives sample code for drawing histogram
http://www.keepedge.com/iphone_charts/histogram_chart.html
You can look at DSBarChart. It does exactly what you want.
http://www.cocoacontrols.com/platforms/ios/controls/dsbarchart
精彩评论