如何在Google diffchart中获取注释

时间:2014-01-18 05:53:00

标签: charts google-visualization

我在我的应用程序中使用谷歌api的差异图表作为条形图。我需要为我的差异图表(条形图)获取注释。但我在这段代码中得到错误。请帮我在diffchart中获取注释。 我使用的代码如下所示。

<script type="text/javascript" src="//www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("visualization", '1.1', {packages: ['corechart']});
            google.setOnLoadCallback(drawChart);
            function drawChart() {
                var oldData = google.visualization.arrayToDataTable([
                    ['Name', 'Popularity'],
                    ['Cesar', 2000],
                    ['Rachel', 4200],
                    ['Patrick', 2900],
                    ['Eric', 8200]
                ]);

                var newData = google.visualization.arrayToDataTable([
                    ['Name', 'Popularity', {role: 'annotation'}],
                    ['Cesar', 370, 'df'],
                    ['Rachel', 600, 'ff'],
                    ['Patrick', 700, 'dfg'],
                    ['Eric', 1500, 'dsf'],
                ]);

                var colChartBefore = new google.visualization.ColumnChart(document.getElementById('colchart_before'));
                var colChartAfter = new google.visualization.ColumnChart(document.getElementById('colchart_after'));
                var colChartDiff = new google.visualization.ColumnChart(document.getElementById('colchart_diff'));
                var barChartDiff = new google.visualization.BarChart(document.getElementById('barchart_diff'));

                var options = {legend: {position: 'top'}, diff: {newData: {widthFactor: 1}}};

                colChartBefore.draw(oldData, options);
                colChartAfter.draw(newData, options);

                var diffData = colChartDiff.computeDiff(oldData, newData);
                colChartDiff.draw(diffData, options);
                barChartDiff.draw(diffData, options);
            }
        </script>

        <span id='colchart_before' style='width: 450px; height: 250px; display: inline-block'></span>
        <span id='colchart_after' style='width: 450px; height: 250px; display: inline-block'></span>
        <span id='colchart_diff' style='width: 450px; height: 250px; display: inline-block'></span>
        <span id='barchart_diff' style='width: 450px; height: 250px; display: inline-block'></span>

我已经从这个link

中引用了这段代码

0 个答案:

没有答案