图表未显示在 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 (将#修改为@)