Google Charts API自定义月份名称 [英] Google Charts API custom month names

查看:82
本文介绍了Google Charts API自定义月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在图表中设置自定义月份名称。

I need to set custom month names in Charts.

如何在Google Charts API中设置自定义月份名称?

How set custom month names in Google Charts API?

推荐答案

您可以在 hAxis 上指定自定义标记 ...

You can specify custom ticks on the hAxis...

      google.load('visualization', '1', {packages: ['corechart']});
      google.setOnLoadCallback(drawChart);

      function drawChart() {

        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Time of Day');
        data.addColumn('number', 'Rating');
        data.addColumn({type: 'string', role: 'tooltip'});

        data.addRows([
          [new Date(2015, 1, 1), 5, 'January'],
          [new Date(2015, 2, 1), 7, 'February'],
          [new Date(2015, 3, 1), 3, 'March'],
          [new Date(2015, 4, 1), 2, 'April'],
          [new Date(2015, 5, 1), 2, 'May']
        ]);


        var options = {
          width: 900,
          height: 500,
          hAxis: {
            format: 'MMM',
            gridlines: {count: 5},
            ticks: [
              {v: new Date(2015, 1, 1), f:'custom 1'},
              {v: new Date(2015, 2, 1), f:'custom 2'},
              {v: new Date(2015, 3, 1), f:'custom 3'},
              {v: new Date(2015, 4, 1), f:'custom 4'},
              {v: new Date(2015, 5, 1), f:'custom 5'}
            ]
          },
          vAxis: {
            gridlines: {color: 'none'},
            minValue: 0
          }
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }

<script src="https://www.google.com/jsapi"></script>
<div id="chart_div"></div>

>

这篇关于Google Charts API自定义月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆