简体   繁体   English

Google图表-Y轴刻度

[英]Google Charts - Scale in Y-Axis

I use Material column charts in my Web App. 我在Web应用程序中使用“ 材料”柱形图

and I have following out 我已经跟进了

在此处输入图片说明

and codes are below, 和代码在下面,

google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
   var data = google.visualization.arrayToDataTable([
              ['Structure', 'Estimated', 'Actual'],
              ['hours', 6, 8],
              ['hours2', 20, 18],                              
            ]);

            var options = {
              chart: {
                title: 'Structures by Hours',
                subtitle: 'Estimated vs Actual',
              }
            };

            var chart = new google.charts.Bar(document.getElementById('columnchart_hours'));

            chart.draw(data, options);

What I want to do two things / need your hand, (on red circled area the image.) 我想做两件事/需要您的帮助 (在红色圆圈处的图像)。

  1. to name the Y-Axis as Hours 将Y轴命名为小时
  2. and make the same axis scale 2 hours by 2 hours so that the Y-Axis / Hours Axis become 2, 4, 6, 8, 10 so on. 并以2个小时乘2个小时来设置相同的轴刻度,以使Y轴/小时轴变为2、4、6、8、10等。

Thanks in advance, 提前致谢,

Need to set configuration options for the vAxis . 需要为vAxis设置配置选项

    vAxis: {
        title: 'Hours',
        ticks: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
    }
  1. Use title for the axis label. 使用title作为轴标签。
  2. Supply an array to ticks for the axis tick marks. 提供一个数组来ticks的轴的刻度线。

However, it doesn't appear ticks works for Material charts. 但是,对于材料图,似乎没有ticks
Note the options have to be converted as well... 请注意,选项也必须转换。
google.charts.Bar.convertOptions

This example shows both a Core chart and a Material chart... 该示例同时显示了核心图和材料图...

 google.load('visualization', '1', { packages: ['corechart', 'bar'], callback: drawBarChart }); function drawBarChart() { var data = google.visualization.arrayToDataTable([ ['Structure', 'Estimated', 'Actual'], ['hours', 6, 8], ['hours2', 20, 18], ]); var options = { chart: { title: 'Structures by Hours', subtitle: 'Estimated vs Actual', }, vAxis: { title: 'Hours', ticks: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] } }; var chart = new google.visualization.ColumnChart(document.getElementById('columnchart_hours')); chart.draw(data, options); var chart2 = new google.charts.Bar(document.getElementById('columnchart_hours2')); chart2.draw(data, google.charts.Bar.convertOptions(options)); } 
 <script src="https://www.google.com/jsapi"></script> <div id="columnchart_hours"></div> <div id="columnchart_hours2"></div> 

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

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