Filling area between two lines - Chart.js v2

后端 未结 3 1272
不知归路
不知归路 2021-01-04 09:50

I am trying to fill the area between two lines in a line chart using Chart.js. Like this:

There is already an answer here, that explains how to extend chartjs to do

3条回答
  •  悲哀的现实
    2021-01-04 10:30

    Setting fill property to +1 of a dataset will set the backgroundColor from this line to the next line in dataset.

    datasets: [{
            label: 'Systolic Guideline',
            data: [],
            fill: '+1',
            borderColor: '#FFC108',
            backgroundColor: 'rgba(255,193,8,0.2)'
          },
          {
            label: 'Diastolic Guideline',
            data: [],
            fill: true,
            borderColor: '#FFC108',
            backgroundColor: 'rgba(0,0,0,0)'
          }]
    

    See this: https://www.chartjs.org/samples/latest/charts/area/line-datasets.html

提交回复
热议问题