本文介绍了尝试在谷歌图表中将y轴设置为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在很多方面(在options4变量中)将y轴的最小值设置为0:

  var options4 = {
chart:{
title:'Temperatura',
subtitle:'Últimas4 horas'
},
vAxes:{
0:{title:'Temperatura'},
1:{title:'Resto'}
},
系列:{
0:{targetAxisIndex:0},
1:{targetAxisIndex:0},
2:{targetAxisIndex:1},
3:{targetAxisIndex:1},
4:{targetAxisIndex:1}
},
width:900,
height:500
};

但是我不能...有任何想法?

vAxes ,您可以使用 viewWindow.min



  google.charts.load('current',{packages:['corechart','line'],callback:drawChart});函数drawChart(){var data4 = new google.visualization.DataTable(); data4.addColumn('date','Hora'); data4.addColumn('number','Temp Casa'); data4.addColumn('number','Temp Fuera'); data4.addColumn('number','Lluvia'); data4.addColumn('number','Humedad'); data4.addColumn('number','Viento'); data4.addRows([[新日期(2016,02,25,19,45),20.375,10.3,0,48,8],[新日期(2016,02,25,20,00),20.312,10.3, 0,48,8],[新日期(2016,02,25,20,15),20.312,10.3,0,48,8],[新日期(2016,02,25,20,30),20.5, [新日期(2016,02,25,20,45),20.562,9,0,55,4],[新日期(2016,02,25,21,00), 20.562,9,0,55,4],[新日期(2016,02,25,21,15),20.5,9,0,55,4],[新日期(2016,02,25,21,30) ),20.437,9,0,55,4],[新日期(2016,02,25,21,45),20.5,8.9,0,60,8],[新日期(2016,02,25,22) ,00),20.437,8.9,0,60,8],[新日期(2016,02,25,22,15),20.375,8.9,0,60,8],[新日期(2016,02,25, ,22,30),20.312,8.9,0,60,8],[新日期(2016,02,25,22,45),20.312,9.3,0.64,9],[新日期(2016,02 ,25,23,00),20.25,9.3,0,64,9],[新日期(2016,02,25,23,15),20.187,9.3,0.64,9],[新日期(2016) ,02,25,23,30),20.125,9.3,0.64,9]]); var options4 = {chart:{title:'Temperatura',subtitle:'Últimas4 horas'},vAxes:{0:{title:'Temperatura',viewWindow:{min:0}},1:{title:'Resto ',viewWindow:{min:0}}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:0},2:{targetAxisIndex:1},3:{targetAxisIndex:1},4: targetAxisIndex:1}},width:900,height:500}; var chart4 = new google.charts.Line(document.getElementById('chart_div4')); chart4.draw(data4,google.charts.Line.convertOptions(options4));}  
 < script src =https://www.gstatic.com/charts/loader.js>< / script>< div id =chart_div4>< / div> ;  


I tried to set the min value of the y axis to 0 in many ways (in the options4 variable) in this Google Chart:https://jsfiddle.net/kurnosem/qn6nrnah/3/

        var options4 = {
            chart: {
                title: 'Temperatura',
                subtitle: 'Últimas 4 horas'
            },
            vAxes: {
                0: {title: 'Temperatura'},
                1: {title: 'Resto'}
            },
            series: {
                0: {targetAxisIndex: 0},
                1: {targetAxisIndex: 0},
                2: {targetAxisIndex: 1},
                3: {targetAxisIndex: 1},
                4: {targetAxisIndex: 1}
            },
            width: 900,
            height: 500
        };

But I can't... any ideas?

解决方案

you can use viewWindow.min for each vAxes

google.charts.load('current', {
  packages: ['corechart', 'line'],
  callback: drawChart
});

function drawChart() {
  var data4 = new google.visualization.DataTable();
  data4.addColumn('date', 'Hora');
  data4.addColumn('number', 'Temp Casa');
  data4.addColumn('number', 'Temp Fuera');
  data4.addColumn('number', 'Lluvia');
  data4.addColumn('number', 'Humedad');
  data4.addColumn('number', 'Viento');

  data4.addRows([
    [new Date(2016,02,25,19,45),20.375,10.3,0,48,8],
    [new Date(2016,02,25,20,00),20.312,10.3,0,48,8],
    [new Date(2016,02,25,20,15),20.312,10.3,0,48,8],
    [new Date(2016,02,25,20,30),20.5,10.3,0,48,8],
    [new Date(2016,02,25,20,45),20.562,9,0,55,4],
    [new Date(2016,02,25,21,00),20.562,9,0,55,4],
    [new Date(2016,02,25,21,15),20.5,9,0,55,4],
    [new Date(2016,02,25,21,30),20.437,9,0,55,4],
    [new Date(2016,02,25,21,45),20.5,8.9,0,60,8],
    [new Date(2016,02,25,22,00),20.437,8.9,0,60,8],
    [new Date(2016,02,25,22,15),20.375,8.9,0,60,8],
    [new Date(2016,02,25,22,30),20.312,8.9,0,60,8],
    [new Date(2016,02,25,22,45),20.312,9.3,0,64,9],
    [new Date(2016,02,25,23,00),20.25,9.3,0,64,9],
    [new Date(2016,02,25,23,15),20.187,9.3,0,64,9],
    [new Date(2016,02,25,23,30),20.125,9.3,0,64,9]
  ]);

  var options4 = {
    chart: {
      title: 'Temperatura',
      subtitle: 'Últimas 4 horas'
    },
    vAxes: {
      0: {
        title: 'Temperatura',
        viewWindow: {
          min: 0
        }
      },
      1: {
        title: 'Resto',
        viewWindow: {
          min: 0
        }
      }
    },
    series: {
      0: {targetAxisIndex: 0},
      1: {targetAxisIndex: 0},
      2: {targetAxisIndex: 1},
      3: {targetAxisIndex: 1},
      4: {targetAxisIndex: 1}
    },
    width: 900,
    height: 500
  };

  var chart4 = new google.charts.Line(document.getElementById('chart_div4'));
  chart4.draw(data4, google.charts.Line.convertOptions(options4));
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div4"></div>

这篇关于尝试在谷歌图表中将y轴设置为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:22