我目前正在使用 JSON 填充我的 Google 图表,但我还需要自定义工具提示。目前我的 JSON 如下所示:
{
"cols": [
{"id": "", "label": "date", "type": "string"},
{"id": "", "label": "price", "type": "number"}
],
"rows": [
{"c":[{"v": "Apr 24th","f":null}, {"v": 56000,"f":"56000"}]},
{"c":[{"v": "May 3rd","f":null}, {"v": 68000,"f":"68000"}]},
{"c":[{"v": "May 13th","f":null}, {"v": 50400,"f":"50400"}]}
]
}
但如果我也像这样在 JSON 中指定我的工具提示:
{
"cols": [
{"id": "", "label": "Date", "type": "string"},
{"id": "", "label": "price", "type": "number"},
{"id": "", "role": "tooltip", "type": "string"}
],
"rows": [
{"c":[{"v": "Apr 24th","f":"null"}, {"v": 56000,"f":"56000"}, {"v": "24 April, Price - 56000, Seller-abcd"}]},
{"c":[{"v": "May 3rd","f":"null"}, {"v": 68000,"f":"68000"}, {"v": "3 May, Price - 68000, Seller-abcd"}]},
{"c":[{"v": "May 13th","f":"null"}, {"v": 50400,"f":"50400"}, {"v": "23 May, Price - 50000, Seller-abcd"}]}
]
}
我收到一条错误消息,表明系列中的所有值都应具有相同的数据类型。
我的客户端代码如下所示:
var jsonData = $.ajax({
url: '../phps/testPhp.php',
dataType:"json",
async: false
}).responseText;
var dataTable = new google.visualization.DataTable(jsonData);
var minVal = 50000;
var maxVal = 70000;
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
var options = {
width: 375, height: 240,
legend: 'none',
pointSize: 5,
backgroundColor: 'transparent',
vAxis: { minValue: 45000, maxValue: 70000 }
};
chart.draw(dataTable, options);
如果有人知道解决方案,请告诉我。