【发布时间】:2012-12-13 07:12:30
【问题描述】:
我的谷歌折线图看起来像这样:
10| .
| .....----''' ''--.
09| .-----''''' ''-
| '.
08| \
| '.
07| '.
|________________________________________________________
2012/12/27 12:01 2012/12/26 12:22 2012/12/25 11:33
我希望它看起来像这样(注意 X 轴标签):
10| .
| .....----''' ''-.
09| .-----''''' \
| '.
08| \
| '.
07| '.
|_______________________________________________
2012/12/27 2012/12/26 2012/12/25
12:01 12:22 11:33
我尝试添加<br>、\n 和\r,但没有成功。
我查看了文档,发现最接近的是hAxis.maxTextLines,但没有minTextLines 选项,所以我不知道如何强制它。我该怎么做?
更新
通过链接到谷歌创建图表时,这似乎是可能的。您只需使用额外的 x 值设置 chxt 变量(无论您需要多少 x 轴):chxt=y,x,x。然后对于每个 x 轴,使用 chxl 变量设置标签。 chxl=1:|2012/12/27|2012/12/26|2012/12/25|2:|12:01|12:22|11:33
例如:
但我创建图表的方式是通过 JavaScript。这样:
google.setOnLoadCallback(function(){
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Count');
//Populate data
new google.visualization.LineChart(document.getElementById('chart')).
draw(data, {curveType: 'function',
chartArea: {left: 70, top: 50, width: '100%', height: '85%'},
width: 950, height: 800,
interpolateNulls: true,
pointSize: 5,
legend: {position: 'none'},
vAxis: {title: 'Count', viewWindow: {min: 7, max: 10}},
hAxis: {title: 'Date', viewWindow: {min: 0, max: 3}}
});
});
所以我需要想办法如何使用这种格式/API 做到这一点。我该怎么做?
【问题讨论】:
-
@JSuar - 你肯定赢得了赏金,但我仍在努力实施你的解决方案。
-
我听到了。这不是最好的解决方案。 Here's a cleaned up version using your code above。重复的 x 轴数据也可以折叠成一个数组,因此您不必存储两次。
-
我上面的解决方案有帮助吗?如果是这样,我可以更新我的答案。
-
是的。继续更新你的答案,我会接受的。
-
答案已更新。很高兴能够帮助您找到解决方案。
标签: javascript svg line-breaks google-visualization