admin管理员组文章数量:1300006
So I tried messing around with my charts and noticed that integers/floats/dates work perfectly fine for the x axis, but the moment that you put in a string, it blows up.
I'm trying to graph a: Word/Count graph, but unfortunately I can't seem to be able to put strings in the x axis. Is this allowed in Google Charts, or is it strictly int/floats/dates?
So I tried messing around with my charts and noticed that integers/floats/dates work perfectly fine for the x axis, but the moment that you put in a string, it blows up.
I'm trying to graph a: Word/Count graph, but unfortunately I can't seem to be able to put strings in the x axis. Is this allowed in Google Charts, or is it strictly int/floats/dates?
Share Improve this question edited Nov 25, 2014 at 5:55 Pratik Butani 62.4k63 gold badges286 silver badges449 bronze badges asked Nov 25, 2014 at 0:51 Stupid.Fat.CatStupid.Fat.Cat 11.3k28 gold badges94 silver badges163 bronze badges2 Answers
Reset to default 4use vAxis and hAxis property as below
google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:600, height:400,
vAxis: {title: "Year",ticks: [{v:100, f:"100$"},{v:150, f:"150$"},{v:200, f:"200$"},{v:300, f:"300$"}]},
hAxis: {title: "Cups",ticks: [{v:4, f:"3-4"},{v:8, f:"5-9"},{v:10, f:"9-13"},{v:14, f:"13-14"},{v:20, f:"15-20"}]} }
);
for more detail check this How to get the vaxis line in column chart of google api chart?
Just define your column to be of type string
and there is no issue. Do note that with a string major column, all rows will be evenly spaced among the chart.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Sales');
data.addRows([
['Jan', 1],
['Feb', 5],
['Mar', 2],
['Apr', 3]
]);
To also use vertical lines in your chart you can not use column type string
but you have to use either number
, float
or date
. To still use strings as x-axis labels you can use ticks
like in the jsfiddle here: http://jsfiddle/j29Pt/417/
本文标签: javascriptGoogle Chart is it possible to use Strings for the x axisStack Overflow
版权声明:本文标题:javascript - Google Chart: is it possible to use Strings for the x axis? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741619683a2388736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论