2015-10-05 88 views
1

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

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

+0

该图表是您使用自定义ticks指定?是数据或轴标签的名称部分?需要更多的继续,例子会很好。 – WhiteHat

+0

请参阅https://jsfiddle.net/s0w4oht1/1/我需要自定义名称为“二月,三月,四月,五月,六月......” – Nopster

+0

任何运气与答案? – WhiteHat

回答

1

您可以将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>

+0

不错,但如果鼠标点在字符上,显示标有月份名称的工具提示 – Nopster

+0

没问题,请参阅编辑... – WhiteHat