Replies: 3 comments 7 replies
-
this is just a plugin for chart.js. So, you should be able to use it using react-chartjs-2 just be sure to register everything in chart.js before using this plugin |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have tried using the code below to create a scatterWithErrorBars but I have not been able to do that: import React, { createRef, useEffect } from "react";
import "./App.css";
import { Chart, registerables } from "chart.js";
import {
PointWithErrorBar,
ScatterWithErrorBarsController,
} from "chartjs-chart-error-bars";
Chart.register(
ScatterWithErrorBarsController,
PointWithErrorBar,
...registerables
);
function ErrorBars() {
const canvasRef = createRef<HTMLCanvasElement>();
useEffect(() => {
const canvas = canvasRef.current;
if (canvas != null) {
const ctx = canvas.getContext("2d");
if (ctx != null) {
// eslint-disable-next-line no-new
new Chart(ctx, {
type: "scatterWithErrorBars",
data: {
labels: ["A", "B"],
datasets: [
{
data: [
{
x: 2,
xMin: 1,
xMax: 3,
y: 4,
yMin: 1,
yMax: 6,
},
{
x: 7,
xMin: 6,
xMax: 9,
y: 2,
yMin: 1,
yMax: 4,
},
],
},
],
},
});
}
}
});
return (
<div>
<canvas ref={canvasRef} id="myChart" />
</div>
);
// return <div>Hi</div>;
}
export default ErrorBars; |
Beta Was this translation helpful? Give feedback.
1 reply
-
To prove that the basic Chart.js library works in React, I have the following code: import React, { createRef, useEffect } from "react";
import "./App.css";
import { Chart, registerables } from "chart.js";
Chart.register(...registerables);
function ChartJsLine() {
const canvasRef = createRef<HTMLCanvasElement>();
useEffect(() => {
const canvas = canvasRef.current;
if (canvas != null) {
const ctx = canvas.getContext("2d");
if (ctx != null) {
// eslint-disable-next-line no-new
new Chart(ctx, {
type: "line",
data: {
//Bring in data
labels: ["Jan", "Feb", "March"],
datasets: [
{
label: "Sales",
data: [86, 67, 91],
},
],
},
options: {
//Customize chart options
},
});
}
}
});
return (
<div>
<canvas ref={canvasRef} id="myChart" />
</div>
);
}
export default ChartJsLine; This is working fine in React. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to use this library to integrate error bars with a scatterplot graph in React (currently using react-chartjs-2). Could you please provide instructions on how I can achieve that? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions