Display: false on dataset Category:Help

Hello,

I got a small problem, and I´m sure someone can help me.

Actually I predefine a line chart with 10 datasets. Now the user can pick up to 10 elements and the data will be automaticly loaded out of my database. Works fine.

The problem is, the user can also pick only 8 elements which would mean only 8 lines have “real” data. Is there anyway to predefine a dataset without making it visible ?

So I can fill it with informations later and display it if I want. Display: false does not work in datasets.

Author: Fantashit

1 thought on “Display: false on dataset Category:Help

  1. If the dataset is hidden and also the legend, how does the user bring it back? For custom controls, you may want to consider hiding the legend altogether and taking over the visibility of datasets. This is what I’ve done.

    1. I set options.legend.display=false so no legend will be shown
    2. I offered my own controls, for example a list of checkboxes labeled with dataset labels. The id of each checkbox is tied to the matching dataset’s index within the datasets array (eg: id=set_1)
    3. I have an event listener to the change event on the checkbox. When user toggles the checkbox, I do the same to the dataset visibility. Below is the logic
    onCheckboxToggle(event){
      var chkbox = event.target; //grab the check box element
      var i = +chkbox.id.substring(4); //get index of dataset
    
      //toggle dataset visibility, then .update() the chart (or maybe .render() ?)
      myChart.config.data.datasets[i].hidden = !myChart.config.data.datasets[i].hidden;
      myChart.update();
    }
    

    This will allow you to control the UI, and hide/show datasets as you wish.

Comments are closed.