简体   繁体   English

如何向Google图表柱形图轴添加文本?

[英]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. 我正在尝试使用Google图表以柱状图样式表示我的技能水平。 However I can't figure out how to add text to my y-axis. 但是我不知道如何在y轴上添加文本。 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. 我要达到的目标是在x轴上以及y轴上的水平,如初学者,中级,高级和专家。

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. 使用带有格式化值的vAxis.ticks。 Check out this life example: https://jsfiddle.net/Balrog30/009nk1fp/ 看看这个生活的例子: 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'}
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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