不使用日期格式的谷歌註釋圖表 (Google Annotated Chart without using Date format)


問題描述

不使用日期格式的谷歌註釋圖表 (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);
}

(by D4v3Loki)

參考文件

  1. Google Annotated Chart without using Date format (CC BY‑SA 2.5/3.0/4.0)

#javascript #annotatedtimeline #Date #google-visualization






相關問題

為什麼我不能在 IE8 (javascript) 上擴展 localStorage? (Why can't I extend localStorage on IE8 (javascript)?)

在 Javascript 中打開外部 sqlite3 數據庫 (Open external sqlite3 database in Javascript)

Javascript:數組中的所有對像都具有相同的屬性 (Javascript: All Objects in Array Have Same Properties)

為什麼我們要在 javascripts 原型中添加函數? (Why do we add functions to javascripts prototype?)

顯示 URL javascript 的最後一部分? (Display the last part of URL javascript?)

Javascript XMLHttpRequest:忽略無效的 SSL 證書 (Javascript XMLHttpRequest: Ignore invalid SSL Certificate)

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

如何從 javascript 對像中獲取名稱和值到新列表中? (How to get name and values from a javascript object into a new list?)

數據未發布..幫助!html,js,firebase (Data not posting.. Help! html,js,firebase)

使用 Node.js 腳本查看表單數據 (Seeing form data with Node.js script)

使用百分比查找範圍內的值 (find the value within a range using percent)

如何通過 react.js 中的組件傳遞變量或數據? (How to pass varible or data through components in react.js?)







留言討論