Reactjs 图表未显示在chart.js中
下面的代码显示的是空图。请帮忙。 我正在以正确的格式传递数据(价格),即对象数组,但其呈现的是空图形,所有值在y轴上重叠,即x=0Reactjs 图表未显示在chart.js中,reactjs,chart.js,react-chartjs,Reactjs,Chart.js,React Chartjs,下面的代码显示的是空图。请帮忙。 我正在以正确的格式传递数据(价格),即对象数组,但其呈现的是空图形,所有值在y轴上重叠,即x=0 import {historyOptions} from '../chartConfigs/chartConfigs' import Chartjs from 'chart.js/auto'; const Graph = ({data}) => { const chartRef = useRef() const {prices, det
import {historyOptions} from '../chartConfigs/chartConfigs'
import Chartjs from 'chart.js/auto';
const Graph = ({data}) => {
const chartRef = useRef()
const {prices, detail} = data
console.log(prices)
useEffect(()=>{
if(chartRef && chartRef.current){
const myChart = new Chartjs(chartRef.current, {
type: "line",
data: {
datasets: [{
label: '# of Votes',
data: prices,
backgroundColor: "rgba(174, 305, 194, 0.5)",
fill: true,
borderWidth: 1
}]
},
options: historyOptions
});
}
}, [])
return (
<div className="bg-white border mt-2 reounded p-3">
<div></div>
<div>
<canvas ref={chartRef} id="myChart" width="400" height="400"></canvas>
</div>
</div>
)
}
export default Graph
从“../chartConfigs/chartConfigs”导入{historyOptions}
从“chart.js/auto”导入Chartjs;
常量图=({data})=>{
常量chartRef=useRef()
const{prices,detail}=数据
控制台日志(价格)
useffect(()=>{
if(当前图表参考和图表参考){
const myChart=new Chartjs(chartRef.current{
键入:“行”,
数据:{
数据集:[{
标签:“#投票数”,
数据:价格,
背景色:“rgba(1743051940.5)”,
填充:是的,
边框宽度:1
}]
},
选项:历史选项
});
}
}, [])
返回(
)
}
导出默认图形