I would like to be able to change the chart type of charts using dimple.js by using a variable. I want for instance to switch from bars to lines. I've tried with no success, it seems simple however! Any idea?
Below is my code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="http://dimplejs.org/dist/dimple.v2.1.0.min.js"></script>
</head>
<body>
<div id="chartContainer">
<script type="text/javascript">
var chartType = "line";
var chartDimple = "dimple.plot." + chartType;
var svg = dimple.newSvg("#chartContainer", 590, 400);
d3.csv("data/test.csv", function (data) { //d3.tsv("data/example_data.tsv", function (data) {
var myChart = new dimple.chart(svg, data);
myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", "Month");
x.addOrderRule("Date");
myChart.addMeasureAxis("y", "Unit Sales");
// myChart.addSeries(null, dimple.plot.bar);
myChart.addSeries(null, chartDimple);
myChart.draw();
});
</script>
</div>
</body>
</html>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…