如何避免谷歌图表中的Y轴负值

时间:2017-05-29 08:07:14

标签: php charts

如何避免谷歌图表中的负值,我在Y轴上尝试了viewWindow:{min:0,},但它仍然只显示负值。  请帮助一下。提前致谢

 <div class="timeline-item">
                    <div id="top_x_div" style="width: 100%; height: 300px;"></div>
</div>

<script type="text/javascript">
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawStacked);

function drawStacked() {
        var data = new google.visualization.arrayToDataTable([
           ['Courses', 'Students'],

          ["Electronics",  2 ],
            ]);

        var options = {



    legend: { position: 'none' },
                 isStacked: true,
                   colors: ['green'],

                    bars: 'vertical', // Required for Material Bar Charts.
                    axes: {
                      x: {
                        0: { side: 'bottom', label: 'Percentage'} // Top x-axis.
                      }
                    },

                    axes: {
                      y: {
                        0: { side: 'bottom', label: 'Students'}, // Top x-axis.
                       /* viewWindow: {
                                     min: 0,
                                    },*/
                      }
                    },  
                vAxis: {
                    viewWindow: {
                        min: 0
                    }
                },

                    bar: { groupWidth: "90%" }
                  };
        var chart = new google.charts.Bar(document.getElementById('top_x_div'));
        chart.draw(data, options);
};
</script>

1 个答案:

答案 0 :(得分:1)

您需要在vAxis选项上设置viewWindow。

vAxis: {
    viewWindow: {
        min: 0
    }
}

Source