gpt4 book ai didi

javascript - plottable.js 折线图中的自定义动画

转载 作者:行者123 更新时间:2023-12-02 15:18:37 26 4
gpt4 key购买 nike

我尝试在数据更新时在plottable.js 中使用自定义动画。下面是我的代码:-

<script type="text/javascript">

var xScale = new Plottable.Scales.Category();
var yScale = new Plottable.Scales.Linear().domain([0,30]);

var xAxis = new Plottable.Axes.Category(xScale, "bottom");
var yAxis = new Plottable.Axes.Numeric(yScale, "left");

var dataset;

var data;

function createChart() {
data = [];

for(var i=0; i<10; i++) {
data.push({x:"Data" + (i + 1),y:Math.abs(Math.random() * 10)});
}

dataset = new Plottable.Dataset(data);
makeChart();
}

function updateChart() {
data = [];

for(var i=0; i<10; i++) {
data.push({x:"Data" + (i + 1),y:Math.abs(Math.random() * 10)});
}

dataset.data(data);
}

function makeChart() {
var linePlot = new Plottable.Plots.Line()
.addDataset(dataset)
.x(function(d) { return d.x; }, xScale)
.y(function(d) { return d.y; }, yScale)
.attr("stroke","#FA8116")
.animated(true)
.animator("test",new Plottable.Animators.Easing().easingMode("bounce"));

var label_y = new Plottable.Components.AxisLabel("Parameter 2", -90);
var label_x = new Plottable.Components.AxisLabel("Parameter 1", 0);

var chart = new Plottable.Components.Table([
[label_y, yAxis, linePlot],
[null, null, xAxis],
[null, null, label_x]
]);

chart.renderTo("svg#lineChart");

// Responsive Layout
window.addEventListener("resize", function() {
chart.redraw();
});
}

$(document).ready(function() {
createChart();
setInterval(function(d) {
updateChart();
},5000);
});

</script>

我想要为默认线图以外的线图设置动画,我这样做了:-

var linePlot = new Plottable.Plots.Line()
.addDataset(dataset)
.x(function(d) { return d.x; }, xScale)
.y(function(d) { return d.y; }, yScale)
.attr("stroke","#FA8116")
.animated(true)
.animator("test",new Plottable.Animators.Easing().easingMode("bounce"));

我不明白我在哪里是正确的,因为我是plottable的新手,你们能帮我吗,还有没有办法在plottable中使用基于d3的动画?如果可以的话可以提供一下代码片段

提前致谢

最佳答案

Plot通常有两个Animator:MAINRESET。您需要指定要更改 Plot 上的主要 Animator:

plot.animator(Plottable.Plots.Animator.MAIN,
new Plottable.Animators.Easing().easingMode("bounce"));

关于javascript - plottable.js 折线图中的自定义动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34263256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com