谷歌图表 - 组合图表 - 2 VAxis需要同步0行

时间:2015-04-06 14:16:28

标签: javascript charts

我是谷歌图表的新手,我遇到了一个我无法弄清楚的问题。

我正在使用ComboChart在条形图上显示每日销售额,左轴上的值和右轴上折线图上的累计月份总数。

它工作正常,除非我们有一天的积分超过销售额,产生负值。这会导致2轴的0线彼此不同步,并且图表看起来不正确。 (见例)

http://i.stack.imgur.com/1VPFD.jpg>

如您所见,右轴从$ 0开始,但左轴缩小至$ -300,000以计算负销售日。

我的图表代码是:

</script><script type="text/javascript">

  // Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawVisualization);    
function drawVisualization() {
  // Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Date', 'Daily Sales', 'Month Total'],
['1', 153638.53, 153638.53], ['2', 342629.97, 496268.50], ['3', 897124.56, 1393393.12], ['4', 0.00, 1393393.12], ['5', -147272.84, 1246120.25], ['6', 113501.20, 1359621.50], ['7', 0.00, 1359621.50], ['8', 0.00, 1359621.50], ['9', 0.00, 1359621.50], ['10', 0.00, 1359621.50], ['11', 0.00, 1359621.50], ['12', 0.00, 1359621.50], ['13', 0.00, 1359621.50], ['14', 0.00, 1359621.50], ['15', 0.00, 1359621.50], ['16', 0.00, 1359621.50], ['17', 0.00, 1359621.50], ['18', 0.00, 1359621.50], ['19', 0.00, 1359621.50], ['20', 0.00, 1359621.50], ['21', 0.00, 1359621.50], ['22', 0.00, 1359621.50], ['23', 0.00, 1359621.50], ['24', 0.00, 1359621.50], ['25', 0.00, 1359621.50], ['26', 0.00, 1359621.50], ['27', 0.00, 1359621.50], ['28', 0.00, 1359621.50], ['29', 0.00, 1359621.50], ['30', 12674.00, 1372295.50]  ]);

var formatter = new google.visualization.NumberFormat({
        decimalSymbol: '.', 
        groupingSymbol: ',', 
        prefix: '$'});
    formatter.format(data, 1);
    formatter.format(data, 2);


var options = {
title : 'Invoice Summary for month of April 2015',

vAxis: {title: "$"},
hAxis: {title: "Date"},
seriesType: "bars",
series: {1: {type: "line", targetAxisIndex: 1}
        },
backgroundColor: { fill:'transparent' }
};

var chart = new google.visualization.ComboChart(document.getElementById('fbinvsummtd'));
chart.draw(data, options);
}
</script>

0 个答案:

没有答案