php - custom logarithmic scale for line-graph -
i kinda stuck problem in jpgraph: need create diagram (line) shows users progress in online-game 6000 other players. y-axis shows users position in ranking , goes 6000 1 (last position first position). x-axis timeline.
so first, x-axis-scale needs inverted - no problem got 1 documentation.
but, have scale "kind of" logarithmic - means want values on x-axis 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 managed scale this, smaller values get, smaller distances between labels. - want have equal distances between every label. - in diagram step 6000-5000 should take space step 50 40 or step 2 1.
hope explain more or less clear. if not add drawing (i suck @ drawing) , sure mean.
if values represented going positive, can make scale negative displays values backwards, jpgraph built display scale on incremental way in case decrease value , make negative values positive.
instead of 1,2,3,4,5 have 5,4,3,2,1 because -5,-4,-3,-2,-1,0,+1,+2,+3,+4,+5 (you invert this) have swap values function.
function _cb_negate ( $aval ) { return round (- $aval ); }
then:
$graph -> xaxis -> setlabelformatcallback ( "_cb_negate" );
for log uses need sort values lowest highest in xaxis since can't use negative values or log values in linear scale in jpgraph need make logarithmic algorithm process values have in array , make them negative values.
hope works!
edit: added example in yaxis, works xaxis too: http://www.asial.co.jp/jpgraph/demo/src/examples/show-example.php?target=inyaxisex1.php
Comments
Post a Comment