Chartjs-Set default line style in chart.js

2👍

As you’ve already seen in the documentation you can set these settings with Chart.defaults.global. Which later get merged with the properties of the dataset.

Chart.defaults.global.elements.line.fill = false;

Settings like fill are found under Chart.defaults.global.elements. Logging the entire Chart.defaults.global object to the console, helps in finding the correct property to set.

Chart.defaults.global.elements.line.fill = false;

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: 'Dataset 1',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
      },
      {
        label: 'Dataset 2',
        data: [6, 8, 4, 2, 4, 8],
        borderWidth: 1,
      },
      {
        label: 'Dataset 3 (filled)',
        data: [7, 11, 5, 8, 3, 7],
        borderWidth: 1,
        fill: true
      }
    ]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          reverse: false
        }
      }]
    }
  }
}

var ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, options);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>

<canvas id="myChart" width="600" height="400"></canvas>

Leave a comment