开发者

how to transform the values to show in graph according to pixels in iphone/ipad?

开发者 https://www.devze.com 2023-02-18 15:00 出处:网络
I need to show values in bar graph. I am drawing the bars using CALayer. And there are only three bars in my case. And the bar height changes for different values. I am drawing each bar as a rectangle

I need to show values in bar graph. I am drawing the bars using CALayer. And there are only three bars in my case. And the bar height changes for different values. I am drawing each bar as a rectangle of variable height( height according to pixcel value).

I am able to draw the maximum height as 300 pix. But, the values in y-axis (height) are 1, 4, 10 1000, 230, 12000 i开发者_运维问答n this way.

How can I scale these values to pixel values? I have to show the values in y-axis ?

Thank you,


This might be a little bit of an old post but why couldnt you take your max possible value:

Say it can never exceed 12,000 / max size you can plot. Then when you create your bars, the size is that % of it.

Example

1, 2, 5, 100, 1000, 10000, 20000 Assuming your max height was 300px... Take the largest number 20,000 and divide by the largest pixel size possible 300px You get .015 percent. This means you multiply each value by .015 and plot it and it should show you a true to scale graph of the values.

0

精彩评论

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

关注公众号