Label y-axis ticks with musical note name

六月ゝ 毕业季﹏ 提交于 2021-02-11 14:56:09

问题


I have a chart data table with series values as numbers (these are MIDI note numbers - e.g. 60 is middle C, 61 is Db).

But for the user, the chart y-axis ticks should be the note names.

How can I do that please?


回答1:


using object notation, you can provide the value (v:) and the formatted value (f:) for each tick

{v: 60, f: 'C4 (middle C)'}

see following working snippet...

google.charts.load('current', {
  packages: ['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    [1, 60],
    [2, 61]
  ], true);

  var options = {
    vAxis: {
      ticks: [
        {v: 60, f: 'C4 (middle C)'},
        {v: 61, f: 'C#4/Db4'},
      ]
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>


来源:https://stackoverflow.com/questions/60947675/label-y-axis-ticks-with-musical-note-name

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