【问题标题】:Google Charts API custom month namesGoogle Charts API 自定义月份名称
【发布时间】:2015-10-05 17:08:09
【问题描述】:

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

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

【问题讨论】:

  • 您使用的是哪个图表?名称是数据或轴标签的一部分吗?需要更多继续,例子会很棒。
  • jsfiddle.net/s0w4oht1/1 我需要自定义名称“Feb, Mar, Apr, May, Jun ....”
  • 答案有什么好运气吗?

标签: javascript charts google-visualization


【解决方案1】:

您可以在hAxis 上指定自定义ticks...

      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>

【讨论】:

  • 很好,但如果鼠标悬停在字符上,则会显示带有标准月份名称的工具提示
猜你喜欢
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
相关资源
最近更新 更多