单页上有更多谷歌排行榜

时间:2016-05-03 15:06:23

标签: wordpress charts google-visualization visualization pygooglechart

我需要在单页上显示多个图表 - 这些图表应该是分开的,而不是在一个块中。我在这里找到了一些建议,但我不知道我的代码中有什么问题。一切正常,直到我改变了行“google.charts.load('43',{packages:['corechart']});”我尝试更改了函数名称,但仍然无法正常工作。我很抱歉我的英语,我很喜欢代码。

图1

<script type="text/javascript"
        src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load('43', {packages: ['corechart']});
    google.charts.setOnLoadCallback(chart2);
function chart2() {
var wrapper = new google.visualization.ChartWrapper(
{"containerId":"2C2D","dataTable":{"cols":[{"id":"","label":"","pattern":"","type":"string","p":{}},{"id":"","label":"CZK","pattern":"","type":"number","p":{}},{"id":"","label":"zbývá CZK","pattern":"","type":"number"}],"rows":[{"c":[{"v":"březen","f":null},{"v":1844,"f":null},{"v":143739,"f":null}]}],"p":null},"options":{"isStacked":true,"animation":{"duration":2500,"startup":true},"bar":{"groupWidth": "25%"},"booleanRole":"certainty","hAxis":{"useFormatFromData":true,"viewWindow":{"max":150000,"min":null},"minValue":null,"maxValue":160000,"logScale":false,"gridlines":{"count":"4"}},"vAxes":[{"useFormatFromData":true,"minValue":null,"maxValue":null,"viewWindow":null,"viewWindowMode":null},{"useFormatFromData":true}],"legend":"bottom","series":{"1":{"color":"#b7b7b7"}},"fontName":"Georgia","title":"Náklady CZK"},"state":{},"view":{},"isDefaultVisualization":true,"chartType":"BarChart"}
);
wrapper.draw();
};
</script>
<div style='border: 0px darkgray solid;width:500px;'>
<div id='2C2D' style='width:500px; height:200px;'></div>
</div>

图2

<script type="text/javascript"
        src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load('43', {packages: ['corechart']});
    google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var wrapper = new google.visualization.ChartWrapper(
{"containerId":"visualizationDCA3","dataTable":{"cols":[{"id":"","label":"","pattern":"","type":"string","p":{}},{"id":"","label":"CZK","pattern":"","type":"number","p":{}},{"id":"","label":"zbývá CZK","pattern":"","type":"number"}],"rows":[{"c":[{"v":"březen","f":null},{"v":62036,"f":null},{"v":2213460,"f":null}]}],"p":null},"options":{"isStacked":true,"animation":{"duration":2500,"startup":true},"bar":{"groupWidth": "25%"},"booleanRole":"certainty","hAxis":{"useFormatFromData":true,"viewWindow":{"max":2500000,"min":null},"minValue":null,"maxValue":2500000,"logScale":false},"vAxes":[{"useFormatFromData":true,"minValue":null,"maxValue":null,"viewWindow":null,"viewWindowMode":null},{"useFormatFromData":true}],"legend":"bottom","fontName":"Georgia","title":"Celkový CZK","series":{"1":{"color":"#b7b7b7"}}},"state":{},"view":{},"isDefaultVisualization":true,"chartType":"BarChart"}
);
wrapper.draw();
};
</script>
<div style='border: 0px darkgray solid;width:500px;'>
<div id='visualizationDCA3' style='width:500px; height:200px;'></div>
</div>

`

1 个答案:

答案 0 :(得分:0)

您可以添加init功能,然后从那里调用其他图表......

&#13;
&#13;
google.charts.load('43', {packages: ['corechart']});
google.charts.setOnLoadCallback(init);

function init() {
  drawChart();
  chart2();
}

function drawChart() {
  var wrapper = new google.visualization.ChartWrapper(
    {"containerId":"visualizationDCA3","dataTable":{"cols":[{"id":"","label":"","pattern":"","type":"string","p":{}},{"id":"","label":"CZK","pattern":"","type":"number","p":{}},{"id":"","label":"zbývá CZK","pattern":"","type":"number"}],"rows":[{"c":[{"v":"brezen","f":null},{"v":62036,"f":null},{"v":2213460,"f":null}]}],"p":null},"options":{"isStacked":true,"animation":{"duration":2500,"startup":true},"bar":{"groupWidth": "25%"},"booleanRole":"certainty","hAxis":{"useFormatFromData":true,"viewWindow":{"max":2500000,"min":null},"minValue":null,"maxValue":2500000,"logScale":false},"vAxes":[{"useFormatFromData":true,"minValue":null,"maxValue":null,"viewWindow":null,"viewWindowMode":null},{"useFormatFromData":true}],"legend":"bottom","fontName":"Georgia","title":"Celkový CZK","series":{"1":{"color":"#b7b7b7"}}},"state":{},"view":{},"isDefaultVisualization":true,"chartType":"BarChart"}
  );
  wrapper.draw();
};

function chart2() {
  var wrapper = new google.visualization.ChartWrapper(
    {"containerId":"2C2D","dataTable":{"cols":[{"id":"","label":"","pattern":"","type":"string","p":{}},{"id":"","label":"CZK","pattern":"","type":"number","p":{}},{"id":"","label":"zbývá CZK","pattern":"","type":"number"}],"rows":[{"c":[{"v":"brezen","f":null},{"v":1844,"f":null},{"v":143739,"f":null}]}],"p":null},"options":{"isStacked":true,"animation":{"duration":2500,"startup":true},"bar":{"groupWidth": "25%"},"booleanRole":"certainty","hAxis":{"useFormatFromData":true,"viewWindow":{"max":150000,"min":null},"minValue":null,"maxValue":160000,"logScale":false,"gridlines":{"count":"4"}},"vAxes":[{"useFormatFromData":true,"minValue":null,"maxValue":null,"viewWindow":null,"viewWindowMode":null},{"useFormatFromData":true}],"legend":"bottom","series":{"1":{"color":"#b7b7b7"}},"fontName":"Georgia","title":"Náklady CZK"},"state":{},"view":{},"isDefaultVisualization":true,"chartType":"BarChart"}
  );
  wrapper.draw();
};
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div style='border: 0px darkgray solid;width:500px;'>
<div id='visualizationDCA3' style='width:500px; height:200px;'></div>

<div style='border: 0px darkgray solid;width:500px;'>
<div id='2C2D' style='width:500px; height:200px;'></div>
&#13;
&#13;
&#13;