Chart.js - How to set a line chart dataset as disabled on load

后端 未结 3 1376
青春惊慌失措
青春惊慌失措 2020-12-14 05:20

Using chart.js v2, is it possible to mark a dataset in a line chart as being disabled on initial load?

Didn\'t find an option for it in the documentation.

3条回答
  •  借酒劲吻你
    2020-12-14 06:06

    If you are using angular-chartjs, then you can add the properties of the dataset in the chart-dataset-override property:

    For example:

    HTML:

    Javascript:

    Chart.defaults.global.legend.display = true;
    
    angular.module("app", ["chart.js"])
      .controller("ChartCtrl", function($scope) {
    
        $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
        $scope.series = ['Series A', 'Series B'];
    
        $scope.data = [
          [65, 59, 80, 81, 56, 55, 40],
          [28, 48, 40, 19, 86, 27, 90]
        ];
    
        $scope.datasetOverride = [{}, {
          hidden: true,
        }];
      });
    

提交回复
热议问题