Google Charts API custom month names

限于喜欢 提交于 2019-12-24 01:37:47

问题


I need to set custom month names in Charts.

How set custom month names in Google Charts API?


回答1:


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>


来源:https://stackoverflow.com/questions/32954062/google-charts-api-custom-month-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!