javascript - Chart.js: hiding series by clicking on legend -
I am developing a site that uses chart.js (www.chartjs.org).
I have to create a line chart that shows more than one series of data, which can hide or show users by clicking on corresponding legend symbol (similar to this).
Is there any way to do this with chartage?
You can try it / Create a store for hidden datasets
< Code> Window.chartName = new chart (... window.chartName.store = new array ();
Then use this function to update the chart, on the legend item It should be controlled by clicking <(Var i = 0; i & lt; store.length; i + +) {if ((if (================== ========== Store [i] [0] === label) {exists = true; chart datasets peyash (store S place (I, 1) [0] [1]); Legend Life. ("Slow", 1);}} if (! Exists) {for (var i = 0; i & lt; chart.datasets.length; I ++) {if (chart.datasets [i] .label === label) {chart.store.push ([Label, chart.datasets.splice (i, 1) [0]]; Legend Lifetime ("slow", 0.33);}}} Chart.update ();}
Do not forget to update legend template in chart options
Legend: " & Lt; (% I = 0 for the square = \ "story-object \" onclick = \ "updateDataset ($ (this), window.chartName, '& lt;% = dataset [i] .label% & gt; ) \ "& Gt; & lt; span style = \" background color: <% = dataset [i] .strokecolor%> gt; & gt; & lt; / span & gt; & lt;% if (Dataset [i] .label) {%> gt; & lt;% = dataset [i] .label% & gt; <%}% & gt; & lt; / li & gt; & lt;%} %> For a while, I added this onclick handler to the li component
For example
Comments
Post a Comment