score:4
Accepted answer
you have to register your own plugin to fill chartarea before chart line drawing:
chart.pluginservice.register({
beforedraw: function (chart, easing) {
if (chart.config.options.fillcolor) {
var ctx = chart.chart.ctx;
var chartarea = chart.chartarea;
ctx.save();
ctx.fillstyle = chart.config.options.fillcolor;
ctx.fillrect(chartarea.left, chartarea.top, chartarea.right - chartarea.left, chartarea.bottom - chartarea.top);
ctx.restore();
}
}
});
var chartdata = {
labels: ['a', 'b', 'c', 'd'],
datasets: [{
label: 'value',
backgroundcolor: 'rgba(255, 0, 255, 0.8)',
bordercolor: 'blue',
data: [30, 50, 25, 10]
}]
};
var ctx = document.getelementbyid("mychart").getcontext("2d");
var mybar = new chart(ctx, {
type: 'line',
data: chartdata,
options: {
scales: {
yaxes: [{ ticks: { max: 60 } }]
},
legend: { display: false },
fillcolor: 'rgba(255, 128, 0, 0.8)',
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.2/chart.min.js"></script>
<canvas id="mychart" height="300" width="500"></canvas>
Source: stackoverflow.com
Related Query
- How to add background color between two lines in yAxis Chartjs
- How to add background color between two specific lines in Chartjs 3.1
- How do I use ChartJS with a background color in the space between two line charts?
- How to set specific height for chartJs background color in terms of yAxis value
- Chartjs Line Color Between Two Points
- How to change the color of legend in chartjs and be able to add one more legend?
- How to set a full length background color for each bar in chartjs bar
- unable to add background color to the canvas using jspdf and chartjs
- How to add ChartJS code in Html2Pdf to view image
- How to add multiple background color in line charts
- How to add background color for doughnut mid using chart,js
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How can I add background color of length bars in chart (chartJS)?
- ChartJs - set background color of the space between ticks
- ChartJS - How to add Text between Pie Chart and Legend
- ChartJs, How can I get different color fills between my two datasets in a line graph?
- Chart.js: Fill background between two lines
- Chartjs Bar Chart add background color to value labels
- How to add space between two scales in chart-js?
- how to add color to each data in chartjs scatter plot
- How can I change the color of certain lines in chartjs / vue-chartjs?
- Fill between two lines Chartjs
- How to add space Between Columns in Bar chartjs and remove the space in the end
- ChartJS Line Charts - remove color underneath lines
- Chart area background color chartjs
- How can I make two of my lines in Chart JS thicker
- How to modify chartjs tooltip so i can add customized strings in tooltips
- Filling area between two lines - Chart.js v2
- ChartJS : How to leave just points without lines
- Chart JS Fill Between two lines
More Query from same tag
- (MVC) Is this an efficient way of displaying chart data by date?
- Vue Chart.js component does not render
- Chart.js margins
- Formatting axis labels using ChartsJS
- Chart.js version 2.5 tooltip align items horizontally
- Catch event of show and hide dataset at chart.js
- Bar Color In Chart JS
- Chartjs chart with only one axis
- How can I change the starting point of horizontal bars in Charts.js
- How to change the z-index of chartjs annotations label?
- Chart.js chart not displaying until I open the browser's console
- How to make interactive a chart with chart.js
- Chart.js Version 3: how to set the different color for tick lines and gridlines
- Hide gridlines in chartjs without the drawTicks
- How to get the X position at a specified chart item index?
- Struggling with dynamic data
- 'filter' function for chart.js legend labels never being called
- Undefined x values in chart.js
- how to add percentage value to legend field in pie chart using chart.js
- Placing JavaScript content in Bootstrap Popover
- Chart.js animations ignoring global default configuration
- Chart.js is not rendered until zoom in in angular 8
- how to use require(chart.js) in codesandbox
- Add new line in es6 inside a doughnut chart
- ChartJS: Percentage labels
- Statistics page - Load every stats <div> one by one
- Chart.js chart appears and disappears on form submit
- Chart.js - Shift/Stagger labels horizontally (for x axis) instead of rotating
- Vue.js - this.<value>.<value> is undefined
- How to show label at right side of Y axis same as left side of Y Axis ChartJS