我正在使用 chartjs 插件实现折线图.我的折线图已绘制加载时从下到上.我想要从左到右的动画线条.我该如何改变?
I am implementing the line graph using chartjs plugin. My line graph is drawn from bottom to top when loading. I would like the lines animated from left to right. How can I change?
你可以在初始化覆盖中扩展图表并覆盖动画的起始值,像这样
You can extend the chart and override the starting values for the animation in the initialize override, like so
Chart.types.Line.extend({
name: "LineAlt",
initialize: function(data){
Chart.types.Line.prototype.initialize.apply(this, arguments);
this.eachPoints(function(point, index){
Chart.helpers.extend(point, {
x: this.scale.calculateX(0),
y: this.scale.calculateY(point.value)
});
point.save();
}, this);
}
});
那么就使用扩展图表,像这样
Then just use the extended chart, like so
...
new Chart(ctx).LineAlt(data);
小提琴 - http://jsfiddle.net/kLg5ntou/