gpt4 book ai didi

dimple.js - 选择新选项时更新dimple.js图表

转载 作者:行者123 更新时间:2023-12-04 22:31:29 26 4
gpt4 key购买 nike

<select  id="cs" name="cs" >
<option value = "HIV+TB" >HIV+TB</option>
<option value = "TB">TB</option>
</select>
<button id="btn">Click Me</button>

<div id="chartContainer">
<script type="text/javascript">
var dropdown = d3.select("#cs")
var cs2 = dropdown.node().options[dropdown.node().selectedIndex].value;
d3.csv("test.csv", function (data) {
var svg = dimple.newSvg("#chartContainer", 590, 600);
var myChart = new dimple.chart(svg, data1990);
myChart.setBounds(105, 25, 475, 465)
myChart.showGridlines = true;
myChart.addCategoryAxis("x", ["measure","sex","year"]);
myChart.addCategoryAxis("y", "age_name");
var z = myChart.addMeasureAxis("z", "rt_mean");
var s = myChart.addSeries("sex", dimple.plot.bubble);
s.aggregate = dimple.aggregateMethod.max;
myChart.addLegend(240, 10, 330, 20, "right");
myChart.draw();
d3.select("#btn").on("click", function() {
myChart.data = data.filter(function(d) { return d.cause_short == cs2; });
myChart.draw(1000);
});
});
</script>

问题是代码想要在现有图表之外添加一个新图表。
单击新选项后如何更新图表。

最佳答案

这是一个在单击按钮时使用随机数重新绘制图表的示例。希望这会给你足够的工作你的例子:

var svg = dimple.newSvg("#chartContainer", 590, 400);
var data = [
{ Animal: "Cats", Value: (Math.random() * 1000000) },
{ Animal: "Dogs", Value: (Math.random() * 1000000) },
{ Animal: "Mice", Value: (Math.random() * 1000000) }
];

var myChart = new dimple.chart(svg, data);
myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", "Animal");
x.addOrderRule(["Cats", "Dogs", "Mice"]);
myChart.addMeasureAxis("y", "Value");
myChart.addSeries(null, dimple.plot.bar);
myChart.draw();

d3.select("#btn").on("click", function() {
myChart.data = [
{ Animal: "Cats", Value: (Math.random() * 1000000) },
{ Animal: "Dogs", Value: (Math.random() * 1000000) },
{ Animal: "Mice", Value: (Math.random() * 1000000) }
];
myChart.draw(1000);
});

这里有一个工作示例:

http://jsfiddle.net/nf57j/

关于dimple.js - 选择新选项时更新dimple.js图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20905429/

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