問題描述
不使用日期格式的谷歌註釋圖表 (Google Annotated Chart without using Date format)
我想使用 Google Charts API 創建一個帶註釋的圖表,就像示例頁面上的那樣:https://developers.google.com/chart/interactive/docs/gallery/annotationchart
但是,我的數據不是日期格式,每列有兩列包含不代表時間的數字。
當我嘗試繪製圖表時,我收到一條錯誤消息,指出第一列必須是日期或日期時間格式。
我試過了通過將第一列更改為:
new Date(0,0,MyNumber)
圖表繪製了我的數據,但 x 軸標籤都是我不想要的日期!如何讓標籤成為我的號碼?
參考解法
方法 1:
To deal with js files I found that there are 2 functions and one variable which needs to be changed. I updated these values manually by yourself and it worked for me
gvjs__a = "number";
gvjs_OD = function (a){return a;};
gvjs_uj = function (a,b,c){return c;}
for example see code below
google.charts.load('current', {'packages':['annotationchart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
**data.addColumn('number', 'TestDate');**
data.addColumn('number', 'Kepler‑22b mission');
data.addRows([
[13, 12400],
[16, 24045]
]);
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var formatter_long = new google.visualization.DateFormat({formatType: 'long'});
var formatter = new google.visualization.DateFormat({pattern: "yy"});
formatter_long.format(data, 0);
var options = {
displayAnnotations: true
};
gvjs__a = "number";
gvjs_OD = function (a){return a;};
gvjs_uj = function (a,b,c){return c;}
chart.draw(data, options);
}