score:6
Accepted answer
In the upcomming release of the V3 version of the lib you can do this with the scriptable options by passing a function to the color key in the tick config instead of a color.
const colors = ['red', 'blue', 'yellow', 'green'];
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
x: {
ticks: {
color: (c) => {
return colors[c.index % colors.length]
}
}
},
y: {
ticks: {
color: (c) => {
return colors[c.index % colors.length]
}
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.0-beta.10/chart.js" integrity="sha512-7igYTuENB1pHNsZ/SyzMYrcJAmRCk084yVOsxNNCQAdX1wSYvCeBOgSOMC6wUdKMO76kCJNOpW4jY3UW5CoBnA==" crossorigin="anonymous"></script>
</body>
Source: stackoverflow.com
Related Query
- Dynamically changing chartjs tick colours
- Dynamically update values of a chartjs chart
- Chartjs random colors for each part of pie chart with data dynamically from database
- Changing fontFamily on ChartJS bar chart
- Dynamically update the options of a chart in chartjs using Javascript
- ChartJs canvas showing previous graph when changing Graph types
- Show data dynamically in line chart - ChartJS
- Changing color of specific chartjs point
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- Chartjs break line for axes tick labels text
- Changing the Y axis unit in Chartjs
- How to dynamically set ChartJs line chart width based on dataset size?
- How to add ChartJS code in Html2Pdf to view image
- Dynamic colours in chartJS based on entries in the array
- ChartJS changing graphs based upon Drop Down selection
- Chartjs tick color different at zero
- Keeping scales in sync across multiple graphs or dynamically changing scales
- dynamically update the scale type of chartjs graph
- Changing the background of a ChartJS on node js
- Meteor and ChartJS dynamically create a chart
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Chartjs not working with d3 from csv source
- Conditional in ChartJS axes tick callback function isn't returning the expected labels
- Chartjs - first x-axis tick is not displayed
- How to prevent tick labels from "jumping" when drawn with ChartJS BeforeDraw
- Changing color of specific ChartJS - AngularChartJS point
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- Show dynamic data with dynamic colours in chartjs
- Chart.js - changing tick / label positions for x axis time series
- How To Match Left and Right Tick Intervals with Chartjs
More Query from same tag
- Ember.Computed is not a function
- (Typescript) How do you set pointRadius, pointHoverRadius, ect in ChartJs 3.7.0 & react-chart-js-2 4.0.1
- Is it possible to revert x-axe values in line chart with chart.js
- Hide/show spefic data in ChartJS
- Adding line over stacked line chart with ChartJS
- chartjs default background color to columns
- Chart.js show tooltips on page load
- Chart.js update() method only works once in the end instead of updating every iteration
- Make months on x-axis clickable on chart.js line chart
- Vuejs with ChartJS populate from API
- How to put static pointDots and make vertical line in Chart.js
- Exclude value if under a certain percentage
- Why is there an error in ChartJs.Blazor (change in ASPNETCORE_ENVIRONMENT)
- Chartjs isn't rendering bar chart, even though chart variable shows correctly when console logged
- How to get line x value from Label chart js
- Why can I not see a data value when hovering over a point on the radar chart?
- Chart.js - Horizontal line on Bar chart interferes with tooltip
- Understanding the data flow when fetching chart data using AJAX
- How to remove legend at the bottom of chartjs doughnuts
- Grouping by month with series of epoch timestamps in Chart.js
- Can't change the time of the xAxes in the Chart.js
- Intersection point in line graph in Chart.js?
- Chartjs columns does not appear by value
- Chart js - Line chart - How to hide the data label on the line?
- Chart.js Timeseries chart - formatting and missing data values
- Page break in Angular with Chartjs and tables
- ChartJS tooltip label for pie cart being cut
- How can i iterate or get all object out of array with object key in Chart.js
- Display ellipsis for null or empty values in the bar chart using Chart.js
- Drawing linear chart without gaps in Chart.js