问题
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