score:20
Accepted answer
You have to set the backgroundColor
property for each of your datasets as well, as that is correspondent to legend box's fill color.
...
datasets: [{
label: 'Ubuntu-based',
fill: true,
data: [0, 0, 0, 0, 51.37, 51.04, 50.64, 50.29, 49.6, 48.32, 47.95, 47.03, 46.42, 46.21],
backgroundColor: '#a6cee3',
borderColor: '#a6cee3',
borderWidth: 1
}, {
label: 'Arch-based',
fill: true,
data: [0, 0, 0, 0, 28.52, 28.53, 28.75, 29.02, 29.16, 30.42, 30.65, 31.29, 31.53, 31.93],
backgroundColor: '#1f78b4',
borderColor: '#1f78b4',
borderWidth: 1
}, {
label: 'Solus',
fill: true,
data: [0, 0, 0, 0, 0.42, 0.45, 0.61, 0.64, 0.92, 1.12, 1.08, 1.21, 1.23, 1.46],
backgroundColor: '#6a3d9a',
borderColor: '#6a3d9a',
borderWidth: 1
}]
...
score:1
var ct = document.getElementById('myChart').getContext('2d');
var Chart = new Chart(ct, {
type: 'line',
data: {
datasets: [{
label: 'test',
data:[1,10],
backgroundColor: "rgb(0, 0, 0, 0)",
borderColor: "rgb(0, 0, 255)",
pointBackgroundColor: "rgb(0, 0, 255)",
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
},
yAxes: [{
scaleLabel: {
display: true,
labelString: 'test'
}
}]
}
},
plugins: [{
beforeDraw: function(c) {
var legends = c.legend.legendItems;
legends.forEach(function(e) {
e.fillStyle = 'red';
});
}
}]
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="myChart" width="400" height="300"></canvas>
Source: stackoverflow.com
Related Query
- chart js how to fill legend box with colour
- How to add a coloured legend box to a pie chart with Chart.js v1?
- Angular chart how to show the legend data value by default along with legend name
- How to add area with break on line chart with fill color
- Chart Js Line chart with fill on click with full information of its legend text
- How to change chart background colour when exporting to PDF with chart.js
- How to fill my chart (chart.js) with my own data from API
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to prevent first/last bars from being cut off in a chart with time scale
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to display Line Chart dataset point labels with Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- chartjs: How to plot multi-line chart with irregular intervals
- How to display inline values in a stacked bar chart with Chart.js?
- ChartJS bar chart with legend which corresponds to each bar
- How to display data labels outside in pie chart with lines in ionic
- Fill Chart.js bar chart with diagonal stripes or other patterns
- How to create a gradient fill line chart in latest Chart JS version (3.3.2)?
- Chart.js HTML custom legend issues with doughnut chart
- How to remove rectangle box next to the legend text in Chart.js
- Chart js: how can I align the legend and the title
- Increase padding between legend and chart with react-chartjs-2
- How can I trigger the hover mode from outside the chart with charts.js 2?
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to add images to chart labels with vue-chartjs?
- how to display chart.js legend with different bar color
- How to create chartjs chart with data from database C#
- How to draw a chart with Chart.JS?
- How to make a chart with an associative array with chart.js?
More Query from same tag
- Only 1 out of 2 ChartJS i showing
- Chartjs with Backbone
- Get the data from node.js for Chart.js
- TopoJson and ChartGeo/ChartJS: Unexpected geomerty
- How to wait for data in useEffect hook before displaying it?
- Displaying line chart for multiple datasets using chart.js
- Chart.js plot not aligned with xAxis labels
- Chart.js change color of Bar
- How to remove header square from chart.js?
- ChartJS customize left and bottom axe border
- Is there a convenient way to print values to a JS chart from a CSV file without converting it?
- How to make integer scale in Chartjs
- Vue and Chartjs - Running a simple example of vue-chartjs
- Append second dataset to existing chartjs chart
- How to display the labels in doughnut chart using ng2 charts?
- Horizontal scroll in vue-chartjs
- time scatter plot w/ chart.js
- ChartJS fails to render horizontal bar chart for timeseries data
- Add multiple lines as Y axis title in chartJs
- how to set start value as "0" in chartjs?
- json_encode returns "
- ChartJS in Datatable cell performance
- ChartJs works with sharepoint 2016 but not sharepoint 2013
- Chartjs / ng2-charts line on hover does not work
- chart.js set one bar as different colour?
- Conditional in ChartJS axes tick callback function isn't returning the expected labels
- live update ecg chart with python and flask
- How to display "%" sign on mouse hover in Pie-Chart
- Chart.js: different dataset size
- Cannot read properties of undefined with react-chartjs-2 and chart js problem