这是条形图的示例。我想在浏览器中打印此条形图,因为我尝试了 react-to-print 但它会抛出错误,例如 react-to-print 仅适用于类组件。
import React from "react";
import { Bar } from "react-chartjs-2";
// dataset for bar chart
const data = {
// goes onto X-axis
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fill: false,
// background color
backgroundColor: "rgba(75,192,192,0.4)",
// border color
borderColor: "rgba(75,192,192,1)",
// goes onto y-axis
data: [65, 59, 80, 81, 56, 55, 40]
}
]
};
const options={
//options for bar chart
};
export const BarDemo = () => {
return (
<div>
<h2>Bar Example</h2>
<Bar data={data} />
</div>
);
};