google.charts.load("current", {
callback: function() {
drawStepChart();
},
packages: ["corechart", "table"]
});
// two sets of values
var values = [
[
[1, 1.22, 'tooltip one', null, null],
[2, 1.22, 'tooltip one', null, null],
[3, 1.22, 'tooltip one', null, null],
[4, 1.22, 'tooltip one', null, null],
[5, 1.22, 'tooltip one', null, null],
[6, 1.55, 'tooltip one', null, null],
[7, 1.55, 'tooltip one', null, null],
[8, 1.55, 'tooltip one', null, null],
[9, 1.90, 'tooltip one', null, null],
[10, 1.90, 'tooltip one', null, null]
],
[
[1, null, null, 2.11,'tooltip two'],
[2, null, null, 2.11,'tooltip two'],
[3, null, null, 2.11,'tooltip two'],
[4, null, null, 0.80,'tooltip two'],
[5, null, null, 0.80,'tooltip two'],
[6, null, null, 0.80,'tooltip two'],
[7, null, null, 0.80,'tooltip two'],
[8, null, null, 1.00,'tooltip two'],
[9, null, null, 2.10,'tooltip two'],
[10, null, null, 2.10,'tooltip two']
]
];
function drawStepChart() {
var data1 = new google.visualization.DataTable();
data1.addColumn("number", "Year");
data1.addColumn("number", "One");
data1.addColumn({type:'string', role: 'tooltip'});
data1.addColumn("number", "Two");
data1.addColumn({type:'string', role: 'tooltip'});
var options = {
animation: { duration: 50 },
areaOpacity: 0
};
var stepchart = new google.visualization.SteppedAreaChart(
document.getElementById("step")
);
var index = 0;
var index2 = 0;
var animate1 = function() {
if (index < values[1].length) {
data1.addRows([values[1][index]]);
stepchart.draw(data1, options);
index++;
} else {
if (index2 < values[0].length) {
data1.setValue(index2, 1, values[0][index2][1]);
data1.setValue(index2, 2, values[0][index2][2]);
stepchart.draw(data1, options);
index2++;
}
}
};
google.visualization.events.addListener(
stepchart,
"animationfinish",
animate1
);
stepchart.draw(data1, options);
animate1();
}
#step {
width: 100%;
height: 500px;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="step"></div>
它的工作!非常感謝你 –