如何解决图表未显示在 chart.js
下面的代码显示的是空图。请帮忙。 我以正确的格式传递数据(价格),即对象数组,但它正在渲染空图,所有值都在 y 轴上重叠,即在 x=0 上。
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。