To the Word-Awesomeness example in dimplejs documentation, I have added 2 series with dimple.plot.bar
and dimple.plot.line
plotFunctions as shown below:
Chart with 2 series:
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.1.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
var svg = dimple.newSvg("body", 800, 600);
var data = [
{ "Word":"Hello", "Awesomeness":2000 },
{ "Word":"World", "Awesomeness":3000 }
];
var chart = new dimple.chart(svg, data);
chart.addCategoryAxis("x", "Word");
chart.addMeasureAxis("y", "Awesomeness");
chart.addSeries(null, dimple.plot.bar);
chart.addSeries(null, dimple.plot.line);
chart.draw();
</script>
</body>
This displays the chart with both line and bar. I would like to hide/show the line and bar based on user selection. I tried removing a series using chart.series.splice (0,1)
and redrawing. That did not work. The chart always shows both bar and line series.
However, the documentation of dimple.chart.series
states that:
This collection is provided for viewing series which have been added with the addSeries method. However it may be modified directly to remove or move a series.
Example:
// Add three series and remove the middle one using a standard JavaScript array operation myChart.addSeries("Brand", dimple.plot.bar); myChart.addSeries("Brand", dimple.plot.bubble); myChart.addSeries("Brand", dimple.plot.line); myChart.series.splice(1, 1);
Please let me know how to hide/show a series selectively in dimplejs. Thanks.