score:1
Accepted answer
For the borderColor to show you need to set the borderWidth to a value bigger then 0, to get the last 20 values you can use a for loop and start 20 values before the end. As last for the different collor bars you can use a scribtable option.
Example:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<canvas id="PM25">test</canvas>
</body>
<script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4"></script>
<script type="text/javascript">
var pm25 = document.getElementById('PM25').getContext('2d');
window.onload = function() {
var dataPoints1 = [];
$.getJSON("https://checkup-7b62e.firebaseio.com/meteo_radauti.json", function(meteo) {
for (i = meteo.length - 20; i < meteo.length; i++) {
dataPoints1.push({
x: meteo[i][0],
y: meteo[i][9]
});
}
var chartColors = {
red: 'rgb(255, 99, 132)',
blue: 'rgb(54, 162, 235)'
};
var PM25 = new Chart(pm25, {
type: 'bar',
data: {
labels: dataPoints1.map(x => x.x),
datasets: [{
data: dataPoints1.map(y => y.y),
label: 'PM2.5 (ppm)',
backgroundColor: (ctx) => (ctx.dataset.data[ctx.dataIndex] > 60 ? chartColors.blue : ctx.dataset.data[ctx.dataIndex] > 40 ? chartColors.red : "green"),
borderColor: chartColors.red,
borderWidth: 1
}, ]
}
});
})
}
</script>
</html>
Source: stackoverflow.com
Related Query
- Charts.js - Bar chart different colors for value intervals not working
- Charts.js - Colors for stacked bar on multi-series line/bar chart are not working
- different colors for bar chart with chart.js
- chart.js Line chart with different background colors for each section
- Chart.js - Line charts with different colors for each border lines
- Different color for each column in angular-chartjs bar chart
- Can't get bar chart colors in Chart js working in React Js
- Chart.js: Minimum value for x-axis at horizontal stacked bar chart
- Vue ChartKick - different colours for bar chart
- How to show different product name for every bar in chart js
- How to retain spacing between bars for two different bar charts in Chart.js 2
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- Click on interactive chart.js bar chart and get value for labels and groups in JS
- Chartjs with Vue, Bar Chart Border Radius not working
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- Chartkick column_chart different colors not working
- How do I get a different label for each bar in a bar chart in ChartJS?
- Chartjs : Can I overwrite bar value on hover for every bar chart
- Chart.js in Angular 10: Specified colors not shown in multi-series bar chart (instead random colors)
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- ChartJS not showing data for time series bar chart
- Legend color not working with randomly generated background colors in chartjs pie chart
- Vertical align bar chart from chart.js not working
- Chart.js colors in bar chart not showing
- chart.js legend not working for pie chart
- Bar animations in 2.0.0-beta/dev are not working for me
- chart.js Second hidden value for Bar Chart
- Why ChartJS's Bar Chart does not render bar for a specific value?
- The colors of the bar chart in chart.js is not showing. I tried background color and fill color but none of it worked
- Chart JS tick options not working for y axis
More Query from same tag
- chart.js - link to other page when click on specific section in chart
- ChartJS multichart graph not showing correctly legends
- Chartjs does not show annotations when x axis is of type time
- Chart.js not working - Uncaught RefernceError:
- is there a way to do automatic scrolling?
- My page is not responsive when I run the with UWSGI
- Chart.JS TypeError: this.scale is undefined
- Chart.js number Y-AXIS label format for many decimal places
- chart.js Line chart doesn't display line past a certain point in the chart
- Not all date data shows on x axis line chart
- Time format on the x axis in Chart.js
- Rotate left legend chartjs
- issue upgrading from chart.js 1 to 3.5
- Chart.js updating-animations of radar-charts
- ChartJS radar scale points
- Can't get Chart.js to run in a Vue.js component
- How to set subscript text in Chart.js axis title
- Draw Line Chart Using Chart.js
- How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
- Datasets in Chart.js stacked barchart appear overlaid instead of stacked
- How to make gap in chart.js graph?
- ChartJS - line graph, position tooltip
- Removing ChartJS 2 border and shadow from point style legend
- Format Bar Chart's yAxis labels in Chart.js
- Charts.js v2: always show custom (html) tooltips on chart
- How to add ChartJS code in Html2Pdf to view image
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- Resetting transform: rotate() by removing and appending canvas not showing data after appending and redrawing chart
- Why ChartJS's Bar Chart does not render bar for a specific value?
- Implementing a choropleth chart using chartjs-chart-geo plugin with react-chartjs-2