はじめに
グーグルチャートの横軸を変更したい。
具体的には、左から今月の1日〜今月末でグラフを表示させたいときに、
ドキュメントが英語パラダイスで、どのoptionsを使うべきなのか理解しづらかったので備忘録。
解決方法
options の hAxis.viewWindow.max/min を使う
var fromThisMonth = new Date(); // 今月の1日
fromThisMonth.setDate(1);
var toThisMonth = new Date(); // 今月末
toThisMonth.setMonth(toThisMonth.getMonth() + 1);
toThisMonth.setDate(0);
var chartType = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
options: {
: //一部options省略
:
hAxis: {
viewWindow: {
min: fromThisMonth, // 最小表示
max: toThisMonth // 最大表示
}
}
}
});
さいごに
日付の両端が2020年10月1日とか2020年10月31日とか出ないのは、
さらに options を追加したり、取得する「時・分」のところまでしっかり指定してあげないといけなかったりいろいろ原因はありそう。。。