javascript - 工具提示中的 Google 折线图日期格式

标签 javascript charts google-visualization

有没有办法更改 Google Chart 中工具提示的日期格式?我不想把它变成 HTML,因为它完全适合我的需要。我只想有其他日期格式。如您所见,我更改了 hAxis 的格式,并且我想对工具提示执行相同的操作。

var data = google.visualization.arrayToDataTable([[{"label":"Month","type":"date"},"Customers"],[new Date('2017-01-01'),30],[new Date('2017-02-01'),45],[new Date('2017-03-01'),55],[new Date('2017-04-01'),40],[new Date('2017-05-01'),20],[new Date('2017-06-01'),17],[new Date('2017-07-01'),15],[new Date('2017-08-01'),18],[new Date('2017-09-01'),0],[new Date('2017-10-01'),0],[new Date('2017-11-01'),0],[new Date('2017-12-01'),0]]);

var options = {"legend":{"position":"bottom"},"pointSize":5,"hAxis":{"format":"MMM","ticks":[new Date('2017-01-01'),new Date('2017-02-01'),new Date('2017-03-01'),new Date('2017-04-01'),new Date('2017-05-01'),new Date('2017-06-01'),new Date('2017-07-01'),new Date('2017-08-01'),new Date('2017-09-01'),new Date('2017-10-01'),new Date('2017-11-01'),new Date('2017-12-01')]},"height":300};

var c = new google.visualization.LineChart(document.getElementById("div-chartw0"));
c.draw(data, options);

enter image description here

最佳答案

在绘制图表之前格式化数据

var formatter = new google.visualization.DateFormat({pattern: 'MMM'});
formatter.format(data, 0);

关于javascript - 工具提示中的 Google 折线图日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42626859/

相关文章:

javascript - 无法将 javascript 变量传递给 php 标记

javascript - 将图像文件附加到表单数据 - Cordova/Angular

python - 在 plotly 中添加组条形图作为子图

mysql - 如何将所有 50 个州设置为国家代码为 'US'

javascript - 使用 JavaScript 在 Web 浏览器中捕获 Apple Remote 事件

javascript - JQuery 选择器重写

javascript - d3 堆叠和缩放

javascript - 谷歌图表 : Set exact Date-boundarys in charts (when using FilterSliders)

google-visualization - 带坐标的谷歌地理图表?

javascript - 为什么我的 javascript ajax 调用有它需要的数据但谷歌图表没有