score:2
well, i used the same node package in a project with different approach kinda work for me. almost all the charts take the same attributes.
basically, this attribute dataset={{ backgroundcolor: ['white', 'yellow' ], }}
is all you need to colour each bar
. you can either pass string or array of string to backgroundcolor.
the backgroundcolor
in dataset takes two types of data string
and array(object)
. typical examples of passing data are below.
- when you set
backgroundcolor
to a string, it applied the same colour to each bar. e.gbackgroundcolor: 'red'
barchart -
<barchart dataset={{ backgroundcolor: 'red', }} />
- when you set
backgroundcolor
to an array, it applied each colour in the array to each bar. e.gbackgroundcolor: ['red', 'yellow']
, then you create a loop of colours base on the data length.
column chart -
<columnchart dataset={{ backgroundcolor: ['red', 'yellow' ], }} />
react implementation below:
/* eslint-disable no-plusplus */
import react from 'react';
import { columnchart, barchart } from 'react-chartkick';
import { chartone } from '../common/chartdata';
import 'chart.js';
const monthlygrowth = () => {
const handlebgcolors = () => {
const firstcolor = "#a00b16", secondcolor = "#faa226";
const arrofbgcolors = [];
for (let i = 1; i <= chartone.length; i++) {
if (i % 2 === 0) {
arrofbgcolors.push(secondcolor)
} else {arrofbgcolors.push(firstcolor)}
}
return arrofbgcolors;
}
return (
<div classname="bukka-card uk-card-default bg-white pt-4 pb-2 mr-1 pl-3 pr-2 pl-
lg-5">
<h2 classname="mt-2">4,500,000</h2>
<barchart
dataset={{ borderwidth: 0, width: 0, backgroundcolor: handlebgcolors(), }}
data={chartone}
/>
</div>
)
}
export default monthlygrowth;
Source: stackoverflow.com
Related Query
- How to set additional options for Chart.js BarCharts using React-Chartkick
- How to use set the color for each bar in a bar chart using chartjs?
- How to set X coordinate for each bar with react chart js 2?
- How do you set x and y axis and Title for a line chart using charts.js?
- How to set up a simple pie chart using React in ChartJS on codesandbox
- how to set chart.js grid color for line chart
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- How to set Solid label in bar chart using Chart JS
- How to set minimal value for bar chart in Chart.js? (ver. 2.0.2)
- getting additional value fields from data source for dx.chartjs doughnut chart
- How to import a doughnut Chart using Chart JS for Blazor?
- How to set up an initial Zoom value for a chart (ChartJS + ChartJS Zoom plugin)?
- How to fix map is not function even there is already set data in the useState using React Hook
- How to run Chart.js samples using source code
- how to create bar chart with group and sam color for each group using chart.js?
- How to set max and min value for Y axis
- How to add text inside the doughnut chart using Chart.js?
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How set color family to pie chart in chart.js
- How to add an on click event to my Line chart using Chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- chartjs : how to set custom scale in bar chart
- Dynamically update the options of a chart in chartjs using Javascript
- How to set default colour for bars in Chart.js
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to Draw Gantt chart using chart js or other libraries
- How to set labels align left in Horizontal Bar using chart.js?
- How to add second Y-axis for Bar and Line chart in Chart.js?
More Query from same tag
- Can i use destroy charts in React.js using Chart.js?
- ChartJS won't recognize JSON my database returns
- How to access custom property in dataset object in Bar Chart in React ChartJS 2?
- remove undefined label in the upper part of a chart
- Chart.js - make background text responsive
- Chart.js 2.9.4 - howto set a margin for axes min\max and time axis label separation
- React Chartjs 2 display axes above datasets backgroundColor
- Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale
- Disable chartJS tool tip on one dataset only
- Bar chart with vertical lines in each bar
- Animated Word Web in Javascript
- Always show last tooltip on all datasets, leave the rest to display on hover? ChartJS
- How to give break line in data label
- dynamically fill a json variable
- Class declaration merging for an existing type
- Why this Tooltip callback for ChartJS works and this doesn't
- space before and after data points in chart.js
- ChartJS - Line Chart with different size datasets
- Chart.js scale x values
- How can I keep my menu from moving other elements in the page?
- How can i iterate or get all object out of array with object key in Chart.js
- Values above points - chart.js
- Chart.js change height on window resize while maintaining aspect ratio
- Emberjs binding properties within Ember object
- Chartjs real time graph x axis movement
- Plotting objects in Chart.js
- Chart JS, backgroundColor not showing
- Chart, X and Y-Axis labels are blurred in horizontal bar chart using chart.js
- How to plot Json data in Chart js
- chart.js set one bar as different colour?