Вопрос

How can I get Google charts to display area charts with an origin from the min value rather than from zero?

In this example, I want the blue area to start from -2000.

Here is the fiddle.. http://jsfiddle.net/C87eD/

function drawVisualization() {
  // Some raw data (not necessarily accurate)
  var data = google.visualization.arrayToDataTable([
    ['Month',   'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda'],
    ['2004/05',    165,      938,         522,             998,           450],
    ['2005/06',    135,      1120,        599,             1268,          288],
    ['2006/07',    157,      1167,        587,             807,           397],
    ['2007/08',    139,      1110,        615,             968,           215],
    ['2008/09',    136,      691,         629,             1026,          366]
  ]);

  // Create and draw the visualization.
  var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
  ac.draw(data, {
    title : 'Monthly Coffee Production by Country',
    isStacked: true,
    width: 600,
    height: 400,
    vAxis: {
      title: "Cups",
      viewWindowMode:'explicit',
      viewWindow: {
        min: -2000
      }
    },
    hAxis: {title: "Month"}
  });
}
Это было полезно?

Решение

One possibility is to use two dummy columns with values -2000 and 2000 to push the first useful values to 0:

  var data = google.visualization.arrayToDataTable([
    ['Month',   'dummy1', 'dummy2', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda'],
    ['2004/05',    -2000, 2000, 165,      938,         522,             998,           450],
    ['2005/06',    -2000, 2000, 135,      1120,        599,             1268,          288],
    ['2006/07',    -2000, 2000, 157,      1167,        587,             807,           397],
    ['2007/08',    -2000, 2000, 139,      1110,        615,             968,           215],
    ['2008/09',    -2000, 2000, 136,      691,         629,             1026,          366]
  ]);

and add option which removes dummy series from legend:

series: {
    0: {
        visibleInLegend: false
    },
    1: {
        visibleInLegend: false
    }
}

See example at jsfiddle.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top