score:11
Accepted answer
You can give an array of colors to pointBackgroundColor property:
var ctx = document.getElementById('lineChart').getContext('2d');
var colors = ["rgba(255,0,0,1)", "rgba(0,255,0,1)", "rgba(0,0,255,1)", "rgba(255,0,0,1)", "rgba(0,255,0,1)"];
var colors1 = Object.assign([], colors);
colors1.sort();
var data = {
labels: [
"1 ",
"2 ",
"3 ",
"4 ",
"5 ",
],
datasets: [{
label: "line 1",
strokeColor: "rgba(151,187,205,1)",
pointRadius: 5,
pointBackgroundColor: colors,
fill: false,
data: [
0.33771896,
0.903282737,
0.663260514,
0.841077343,
0.172840693,
],
}, {
label: "Average",
strokeColor: "rgba(245, 15, 15, 0.5)",
pointBackgroundColor: colors1,
pointRadius: 5,
fill: false,
data: [0.70934844,
0.562981612,
0.496916323,
0.410302488,
0.55354621
]
}]
};
var options = {
datasetFill: false,
}
var myChart = new Chart(document.getElementById("lineChart"), {
type: 'line',
data,
options
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<div>
<canvas id="lineChart" width="600" height="200"></canvas>
</div>
Source: stackoverflow.com
Related Query
- How to change the color of Chart.js points depending on the label
- How to change the label color in chart.js?
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- How to change color by clicking on the chart bar?
- In ChartJS how do I change the color of a label in the legend?
- how to change the label color and set y-axis values 1k intervals and hide y-axis?
- How can i change the every legend label font color using chart.js version 2.8.0 (spacial line chart)?
- How to change label color of ng2 chart in angular
- Chart JS show multiple data points for the same label
- How to change the color of legend in chartjs and be able to add one more legend?
- How do I change the 'months' language displayed on the date axis in Chart JS?
- Chartjs change the specific label color in x axis in callback function
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to change cursor style to pointer on hovering over points of the chart?
- PrimeNg bar chart how to show a label for the y-axis
- How to show only the data points that have a change in Chartjs?
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- How to change line segment color based on label value in chart.js?
- Chart.js color change of the data points
- How to change color of column in chart js
- How to use set the color for each bar in a bar chart using chartjs?
- angular-chart.js doughnut chart : How do I change width of the arc of a doughnut?
- Change the background color of tooltip dynamically using chart color
- How can I change the label name when you hover your data in Chart.js?
- How to change the chart line or area colors according to the user need?
- How to change background color of labels in line chart from chart.js?
- How to change default label of each bubble in bubble chart using chartjs-plugin-datalabels
- How to rotate the Label text in doughnut chart slice vertically in chart.js canvas, Angular 12?
- Chart JS, ng2-Charts - How to make the label to the right of pie chart instead on top?
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
More Query from same tag
- Render pie chart datasets out of 100% -- Chart.JS
- Chart.js bar chart label gets hidden on hover
- My for loop does not iterate in Javascript
- How to get Data from API to display chart using chartjs in Vuejs
- chart.js remove lower grid from mixed chart
- Passing the same props while rendering different elements conditionally in React.js
- why isnt vue-chartjs receiving data from api?
- Chart.js - Why the chart cannot rendered in a child component but in the father component can?
- Chart.js Version 1 differences and can they be achieved in version 2?
- Unable to access data in collection for chart.js
- Ng2-charts + How to customize the position of X axis labels?
- Chart.js get the nearest point when clicked on canvas
- Draw a line around a single point in the linechart
- Move chart x axis label and borders
- Edge does not set height on canvas properly
- Problem displaying two graphs on a single chart using javascript and chart.js
- How to dynamically link json data to chart.js
- Chartjs bar chart trying to get labels from datasets
- How do I get the current step size of a chartjs chart whose stepSize I have not defined?
- How to show labels above pie chart in chart.js
- Chart.JS Can not read property '_meta' of Undefined
- Use multi data to draw chart with chartjs
- Charts.js candlestick (Financial Charts) displays half the bar in the beginning and the end
- Chart.js runs in JSFiddle but not local "Chart is not defined"
- Javascript : import produces a syntax error
- Chart.js error: type lacks a call signature '((...items: number[]) => number) | ((...items: ChartPoint[]) => number)' in Angular
- How to apply data dynamically on initialisation for chart.js in angular?
- Where does chartjs document what is required in the myChartConfig to instantiate using myChart = new Chart(ctx, myChartConfig)
- Dynamic id with canvas on html and angular
- Chart JS in React doesn't fetch data