Skip to content Skip to sidebar Skip to footer

Google Line Chart Starting Coordinate?

How to set the line chart setting so lines begin at x:0 , and not in some random way? Is there a prop for this, or i need to stack up more data????

Solution 1:

If your x values are numeric you can give the option hAxis: {minValue:0} to the draw function :

function drawVisualization() {
  // Create and populate the data table.vardata = 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}}
          );
}

Try this code here : http://code.google.com/apis/ajax/playground/?type=visualization#line_chart

Post a Comment for "Google Line Chart Starting Coordinate?"