我有这个数据,我用于谷歌图表趋势(类型=指数),我已设置第一列编号与下面的数据。
[[{"label":"SecuredYear","type":"number"},{"label":"ValueInDhs","type":"number"}],[2014,14715525.225000001],[2015,14445752.777]]
但是当图表被绘制时,它从2014.0 2014.5 2015.0和2015.5制作了4条垂直线,但我每年只需要一条线,我们是否可以获得标点,以及如何删除y和x显示时将鼠标悬停在 感谢
答案 0 :(得分:0)
有几个选项可以纠正x轴标签/网格线......
1)使用hAxis.ticks
选项仅强制使用两个标签
(使用hAxis.format
删除任何逗号/小数)
hAxis: {
format: '0',
ticks: [2014, 2015]
},
请参阅以下工作代码段...
google.charts.load('current', {
callback: function () {
new google.visualization.LineChart(document.getElementById('chart_div')).draw(
google.visualization.arrayToDataTable([
[
{"label":"SecuredYear","type":"number"},
{"label":"ValueInDhs","type":"number"}
],
[2014,14715525.225000001],[2015,14445752.777]
]),
{
hAxis: {
format: '0',
ticks: [2014, 2015]
},
tooltip: {
trigger: 'none'
}
}
);
},
packages:['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
2)使用年份的字符串,而不是数字......
google.charts.load('current', {
callback: function () {
new google.visualization.LineChart(document.getElementById('chart_div')).draw(
google.visualization.arrayToDataTable([
[
{"label":"SecuredYear","type":"string"},
{"label":"ValueInDhs","type":"number"}
],
['2014',14715525.225000001],['2015',14445752.777]
]),
{}
);
},
packages:['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
如果我按照删除y并在正确悬停时显示x,则
使用tooltip.trigger: 'none'
删除悬停时的工具提示
tooltip: {
trigger: 'none'
}
如上例所示......
答案 1 :(得分:0)
trendlines: { 0: {} } // Draw a trendline for data series 0.
https://developers.google.com/chart/interactive/docs/gallery/trendlines
完整答案:
{
hAxis: {
format: '0',
ticks: [2014, 2015]
},
tooltip: {
trigger: 'none'
},
trendlines: { 0: {} }
}