score:-1
Here is a small plugin that can do shading between any two dataset lines.
score:3
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
score:27
Make sure you import the 2.6.0 version:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
Then follow the rules as described here: http://www.chartjs.org/docs/latest/charts/area.html
Below is an example, and how it looks:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My two lines with colour between them</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
</head>
<body>
<canvas id="mychart" width="300" height="200"></canvas>
<script>
var ctx = document.getElementById('mychart').getContext('2d'); //get the context (canvas)
var config = { //configure the chart
type: 'line',
data: {
labels: [1, 2, 3, 4],
datasets: [{
label: "Min",
backgroundColor: 'rgba(55, 173, 221, 0.6)',
borderColor: 'rgba(55, 173, 221, 1.0)',
fill: false, //no fill here
data: [5, 5, 3, 2]
},
{
label: "Max",
backgroundColor: 'rgba(55, 173, 221, 0.6)',
borderColor: 'rgba(55, 173, 221, 1.0)',
fill: '-1', //fill until previous dataset
data: [8, 7, 6, 5]
}]
},
options: {
maintainAspectRatio: false,
spanGaps: false,
elements: {
line: {
tension: 0.000001
}
},
plugins: {
filler: {
propagate: false
}
},
scales: {
xAxes: [{
ticks: {
autoSkip: false
}
}]
}
}
};
var chart = new Chart(ctx, config);
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- Filling area between two lines - Chart.js v2
- Chart JS Fill Between two lines
- How can I make two of my lines in Chart JS thicker
- Center point labels between ticks (Polar Area Chart JS)
- Find intersection between the chart lines in chartjs
- How to add background color between two lines in yAxis Chartjs
- How to add background color between two specific lines in Chartjs 3.1
- change space between horizontal (grid) lines for line chart
- How to increase space between label and chart area in chart.js
- Mixed Chart calculating difference between two bars - ChartJS
- Chart.js line chart looking as area chart with smooth lines but not sharp
- Chart.js: Fill background between two lines
- Chart.js customization, two Y-Axis overlay, chart area padding, odd tick padding
- Fill between two lines Chartjs
- Chart area background color chartjs
- Chart.js - Increase spacing between legend and chart
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- Chart.js responsive option - Chart not filling container
- Hover/click area in filled line chart in chart.js
- Chartjs Line Color Between Two Points
- chartjs - top and bottom padding of a chart area
- How to display data labels outside in pie chart with lines in ionic
- ChartJS Radar Chart radar lines color?
- Chart.js line chart with area range
- ChartJS disable gridlines outside chart area
- Chart js: Update line chart having two data sets
- Increase padding between legend and chart with react-chartjs-2
- Chart,js Pie Chart can the gap between a pie chart and the legend be adjusted
- Chart.js :set yAxis point to 0 when there is gap between two dates
More Query from same tag
- Resetting transform: rotate() by removing and appending canvas not showing data after appending and redrawing chart
- Customise size of data points , height and width in Chart.js?
- How to reduce the number of data points displayed in react-chart-js2 (data decimation)
- Chart.js - Multiple Doughnut Charts on same Canvas
- Chartjs show hidden data on tooltip
- Why is my line chart using multiple lines to connect random points? (Chart.js)
- chart.js hide gridline inside chartarea but keep y-axis border
- In chart.js, how to know if a yAxes tick is bumping/rendering over/into another
- How to remove strikethrough from label once click on legend
- Chart.js axes label font size
- How to update chart.js on websocket event?
- How to display grouped bar chart using chart.js?
- How to control visibility of canvas image via button outside the canvas(ChartJs)?
- React-chart does not render the legend for PIE chart
- Use chartjs-plugin-annotation 0.5.7 in Chartjs 2.9.x with React
- Chart JS custom tooltip option?
- ChartJS - adding scroll to horizontal legend in Line chart
- How to set additional options for Chart.js BarCharts using React-Chartkick
- Loading an external JSON into ChartJs
- Changing labels with logo images
- toDataURL() gives checkered background to downloaded chart
- Display multiple data into chart.js
- Chart.js 2.x: labels displaying over eachother
- Test a Chart.js canvas with Protractor
- How to add space between two scales in chart-js?
- Chart.Mvc scale begin at 0 - Nullable bool property remains null
- React ChartJS 2 : Get data on clicking the chart
- Chart JS Error: Chart is not defined Firefox
- Chart.js angular8 Y axis ticks
- chart.js mixed chart types