简体   繁体   中英

How do I add text to google charts column chart axis?

I am trying to use google charts to represent my skill levels in the column chart style. However I can't figure out how to add text to my y-axis. What I am trying to achieve is the skills along the x-axis and levels on the y-axis like beginner, intermediate, advanced and expert.

My code:

google.load("visualization", "1", {packages:["corechart"]});
function drawData(){

var data = google.visualization.arrayToDataTable([

        ['Skill','Skill Level', { role: 'style' }],
        ['Graphic Design', 8.94, 'blue'],            
        ['Branding', 21.45, 'red' ],
        ['Photoshop CC', 21.45, 'green' ], 
        ['Illustrator CC', 200, 'yellow' ],
    ]);
var options = {
    legend: {position: 'none'},
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
google.setOnLoadCallback(drawData);

Use vAxis.ticks with a formatted value. Check out this life example: https://jsfiddle.net/Balrog30/009nk1fp/

options.vAxis = {
  ticks: [
    {v: 0, f: 'Nap Time'},
    {v: 2.5, f: 'Bored'},
    {v: 5, f: 'Productive'},
    {v: 7.5, f: 'Excited'},
    {v:10, f: 'Caffeine Overload'}
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM