开发者

custom logarithmic scale for line-graph

I am kinda stuck with this problem in jpgraph: I need to create a diagram (line) that shows the users progress in a online-game with about 6000 other players. So the y-axis shows the users position in the ranking and goes from 6000 to 1 (last position to first position). the x-axis is the timeline.

So first, the x-axis-scale needs to be inverted - no problem got that one with the documentation.

But, I would like to have the scale "kind of" logarithmic - means I want the values on the x-axis like this: 6000, 5000, 4000, 3000, 2000, 1500, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 50,开发者_运维百科 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

I already managed to get a scale like this, but the smaller the values get, the smaller get the distances between the labels. - What I want is to have equal distances between every label. - so in the diagram the step from 6000-5000 should take as much space as the step from 50 to 40 or the step from 2 to 1.

Hope I could explain it more or less clear. If not I will add a drawing (I suck at drawing) and I am sure everyone will get what I mean.


If the values represented are only going to be positive, then you can make the scale negative so it displays the values backwards, JPGraph is built to display the scale on an incremental way in this case you would decrease the value and make the negative values positive.

Instead of 1,2,3,4,5 you would have 5,4,3,2,1 because -5,-4,-3,-2,-1,0,+1,+2,+3,+4,+5 (you would invert this) all you have to do is swap the values with a function.

function _cb_negate ( $aVal ) { 
 return round (- $aVal ); 
} 

Then:

$graph -> xaxis -> SetLabelFormatCallback ( "_cb_negate" );

For log uses you need to sort the values from lowest to highest in the xaxis since you can't use negative values OR for log values to be in a linear scale in jpgraph you would need to make a logarithmic algorithm to process the values that you have in the array and make them negative values.

Hope it works!

EDIT: Added example in yaxis, works with xaxis too: http://www.asial.co.jp/jpgraph/demo/src/Examples/show-example.php?target=inyaxisex1.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜