我試圖暗示一個條形圖我在這里做錯了什么?
在這里我也收到錯誤說要使用打字稿
formatter: (value: number) => value " %",
但我只使用 .js 格式
import { Chart } from "chart.js";
import { Bar } from "react-chartjs-2";
import ChartjsPluginStacked100 from "chartjs-plugin-stacked100";
import "chart.js/auto";
import ChartDataLabels from "chartjs-plugin-datalabels";
Chart.register(ChartDataLabels);
const ExampleChart = () => (
<Bar
data={{
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
backgroundColor: "#EC932F",
borderColor: "rgba(255,99,132,1)",
borderWidth: 1,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
data: [65, 59, 80, 81, 56, 55, 100],
borderRadius: 50, // Make Rectangle rounded
},
],
}}
options={{
indexAxis: "y", // Horizontal bar
plugins: {
datalabels: {
formatter: (value: number) => value " %", // Add the percentage after the value
align: "end",
anchor: "end",
clip: true, // Hide label if outside of the chart
},
},
scales: {
x: {
grid: {
display: false, // Hide x grid
},
},
y: {
grid: {
display: false, // Hide y grid
},
},
},
}}
/>
);
export default function bar() {
return (
<div className="">
<ExampleChart />
</div>
);
}
uj5u.com熱心網友回復:
好像您正在使用.js檔案中的型別。
從格式化程式功能中洗掉打字
formatter: (value) => value " %", // Add the percentage after the value
作業堆疊閃電戰
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/449373.html
標籤:javascript 反应
