javascript - how to make the vAxis and hAxis number in integer -


here code:

 var rawdata='".$performances."';             var mydata=jquery.parsejson(rawdata);             if(mydata){                 var realdata=[];                 realdata=[                       ['activities', 'performance'],                     ];              (x in mydata)             {                 var a=parsefloat(mydata[x]['activities']);                 var b=parsefloat(mydata[x]['performance']);                 realdata[x]=[a,b];             }             var data = google.visualization.arraytodatatable(realdata);             var options = {               title: 'overall performance',               legend: { position: 'top', maxlines: 3 },               haxis: {title: 'activities'},               vaxis: {title: 'performance'}              };              var chart = new google.visualization.linechart(document.getelementbyid('chart_div_line'));             chart.draw(data, options); 

and output is:

enter image description here

i want change current x axis value integer: 1,2,3,4,...., how can it?

thanks in advance.

there couple different approaches can take fix this. first set axis range , gridline count chart defaults showing integer values, eg:

vaxis: {     viewwindow: {         min: 0,         max: 2     },     gridlines: {         count: 3     } } 

generally, if min , max integers , (max - min) / (count - 1) integer, gridlines (and hence axis labels) fall on integer values. approach works best y-axis when know range of valid values chart; can use x-axis too, don't see used often.

the other approach use h/vaxis.ticks option specify locations of gridlines , labels. ticks option takes array of values or objects. values specify location of gridline. objects have v , f properties; v property specifies location of gridline , f property specifies label use. values or objects without specified f property generate axis label according axis format option.

haxis: {     ticks: [1, 2, 3, 4] } 

or:

haxis: {     ticks: [{v: 1, f: 'one'}, {v: 2, f: 'two'}, {v: 3, f: 'three'}, {v: 4, f: 'four'}] } 

you can mix , match objects , values in array like. approach works equally both x , y axes.

you can take 1 approach 1 axis , other approach other axis, if mix them on same axis, aware ticks option overrides gridlines.count, , if place tick mark outside range of viewwindow settings, not see it.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -