score:2
There is a React wrapper around ChartJS available from ReactJS organisation on GitHub. It does support bar charts. Maybe try this (if not as a solution, then as a source of inspiration)
score:0
You might want to take a look at a library named Recharts. I think it is a wrapper that uses Chartjs internally and has built in components for different types of charts which you can leverage to built your own charts by supplying data. It might not be fully customizable but surely will help to have a cleaner implementation as long as your React code in concerned to have basic chart components
score:0
Here is a wrapper component built with newer React hooks
export default function Graph({ className, maxHeight, type, data, options }) {
const graphRef = useRef(null);
useEffect(() => {
if (graphRef.current) {
new Chart(graphRef.current.getContext("2d"), {
type,
data,
options,
});
}
}, [graphRef.current, type, data, options]);
return (
<div className={className || ""}>
<canvas ref={graphRef} style={maxHeight ? { maxHeight } : null} />
</div>
);
}
And use like below to pass data to chart.js
<Graph
className="col-md-4"
maxHeight="200px"
type="bar"
data={{...}}
options={{...}}
/>
score:1
I have been using react-chartjs-2
for quite some time with all my react
projects. It is also a wrapper around chartjs library so you can access all the functionalities as mentioned in the chartjs
documentation.
You can go through the npm library of react-chartjs-2 for more info https://www.npmjs.com/package/react-chartjs-2
score:29
I have been using react-charjs and react-chart-js2 and it seems they have their own limitation if you want more control you can directly use Chartjs in you component.
import React from "react";
var Chart = require("chart.js");
class Layout extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
const node = this.node;
var myChart = new Chart(node, {
type: "bar",
data: {
labels: ["Red", "Blue", "Yellow"],
datasets: [
{
label: "# of Likes",
data: [12, 19, 3],
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(54, 162, 235, 0.2)",
"rgba(255, 206, 86, 0.2)"
]
}
]
}
});
}
render() {
return (
<div>
<canvas
style={{ width: 800, height: 300 }}
ref={node => (this.node = node)}
/>
</div>
);
}
}
export default Layout;
Source: stackoverflow.com
Related Query
- Using Charts.js with react
- Switching between Charts with chart.js using Buttons
- Multipe doughnut charts on one page with text in center using Chart.js
- How to map multiple charts with chart.js in react
- trouble with making floating bar charts using chart.js
- Visualization of charts using real time data from MSSQL with node.js webserver
- Can i use crosshairs with OHLC/candlestick charts using ChartJS
- Chart changes different on zoom when using multiple charts with chart.js and flask
- Get data from SQLite as an array and generate charts with the data using Chart.js in an HTML
- Rest api / json error while using it with react chartjs
- Error Message when using ChartJS with React
- How to run Chart.js samples using source code
- Page with multiple chart.js charts to pdf
- What's the most effective way to implement a radar plot with 50 points at arbitrary locations using chart.js
- Display line chart with connected dots using chartJS
- Using CSS variables (color) with chart.js - "var(--primaryColor)" not working
- How to drill down charts with ChartJS?
- How to save Chart JS charts as image without black background using blobs and filesaver?
- ChartJS - Donut charts with multiple rings
- How to add images as labels to Canvas Charts using chart.js
- Chart.js tooltips callback function with pie charts
- TypeError: Cannot read property 'defaults' of undefined when using the react wrapper of chartjs
- Chart.js - Line charts with different colors for each border lines
- How to zoom charts in chart.js using angular 7
- Chart.js - displaying multiple line charts using multiple labels
- Exporting chart.js charts to svg using canvas2svg.js
- Draw two plots using chartjs over one another with transparency
- Chart.js with React
- Add zoom event handler to charts for chartjs with chartjs-plugin-zoom
- Multiple charts in one page with chart.js
More Query from same tag
- How to set max ticks count in chart.js 3.*.*
- Bar chart not starting at 0
- chartJS: How to return the closest x-axis label on click
- how to add FAHRENHEIT symbol in chart js donut chart
- yAxis control for stacked bar chart
- Chart.js what is the new syntax for extending?
- Vue-Charts label numbers to the side of a bar chart
- create a multi line chart using Chart.js
- space before and after data points in chart.js
- Chart JS how to display an array of data objects as bar chart
- Why my buttons does not work?
- Angular js install external library failed to instantiate module npm
- Chart js: how can I align the legend and the title
- Vertical Bar Chart not displaying Correctly
- Creating charts (charts.js) values coming from SQLite database using AngularJS
- How to get rid of the white square outline or border in the tooltip for chartjs?
- chart.js radar pointLabel options not working
- Chart.js Bar Chart - how to chart bars from 0
- Adding a Date adapter for Time Cartesian axis from a cdn
- Uncaught TypeError: Cannot read property 'format' of undefined
- Chart.js not working - Uncaught RefernceError:
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- Updating Chartjs Data with Response from POST Call?
- ChartJS 2.7.0 updating and exporting as png
- Angular chart js how to use formatter with Doughnut chart
- Parsing json in jQuery error
- Graph made with chart js wont change size?
- Chart.JS removing data stuck in loop
- Blazor ChartJs: Expanding bar to the end of the canvas
- Chartjs - Stacked bar chart blocking other values