Google Line Chart的起始坐标?

时间:2012-03-01 12:50:06

标签: javascript charts google-visualization

如何设置折线图设置,使线条从x:0开始,而不是以某种随机的方式?

enter image description here

是否有支持这个,或者我需要堆积更多数据????

1 个答案:

答案 0 :(得分:1)

如果你的x值是数字,你可以给 draw 函数选择hAxis: {minValue:0}

function drawVisualization() {
  // Create and populate the data table.
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'x');
  data.addColumn('number', 'Cats');
  data.addColumn('number', 'Blanket 1');
  data.addColumn('number', 'Blanket 2');
  data.addRow([0, 1, 1, 0.5]);
  data.addRow([1, 2, 0.5, 1]);
  data.addRow([2, 4, 1, 0.5]);
  data.addRow([3, 8, 0.5, 1]);
  data.addRow([4, 7, 1, 0.5]);
  data.addRow([5, 7, 0.5, 1]);
  data.addRow([6, 8, 1, 0.5]);
  data.addRow([7, 4, 0.5, 1]);
  data.addRow([8, 2, 1, 0.5]);
  data.addRow([9, 3.5, 0.5, 1]);

  // Create and draw the visualization.
  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data, {curveType: "function",
                  width: 900, height: 400,
                  hAxis: {minValue:0},
                  vAxis: {maxValue: 10}}
          );
}

在此处试用此代码:http://code.google.com/apis/ajax/playground/?type=visualization#line_chart