我正在使用JSON填充我的Google圖表,但我也需要自定義工具提示。目前我的JSON是這樣的:使用JSON填充圖表時Google Chart中的工具提示
{
"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);
請讓我知道,如果有人知道的解決方案。
嗨,是的它工作:-)謝謝 – Smriti
有用的信息;接受迴應;-) –
感謝您指引我在正確的方向。我稍微擴展了你的答案。如果你批評它,我將不勝感激。 UPVOTED :) –