如何在ReactJS中扩展chartjs折线图以同时显示实线和虚线?

我想 使用ChartJS在REact JS中一起绘制实线和虚线 ,例如“ https://jsfiddle.net/3gxjfndm/3/”。由于无法获取上下文(ctx),我无法理解如何在我的react js文件中扩展图表。我了解基本概念,但是无法在我的React Component上实现。

以下是我的折线图实现,我认为这是一个BAD实现。

import Chart from 'chart.js';

class LineChart extends React.Component {
    constructor(props) {
        super(props);
        this.canvasRef = React.createRef();
    }

  componentDidmount() {
    this.myChart = new Chart(this.canvasRef.current,{
        type: 'line',options: {
            responsive: true,tooltips: {
                mode: 'index',intersect: false,},hover: {
                mode: 'nearest',intersect: true
            },legend:{
                display:false,scales: {
                x: {
                    display: true,scaleLabel: {
                        display: true,labelString: 'Month'
                    }
                },y: {
                    display: true,labelString: 'Value'
                    }
                }
            }
        },data: {
            labels: ['A','B','C','D','E','F','G','H','I','J','K'],datasets: [{
                label: "My First dataset",data: [1,8,3,4,2,4],borderColor: '#66f',borderDash: [20,30],pointBackgroundColor: "transparent"
            },{
                label: "My Dotted dataset",data: [null,null,7,5,2],pointBackgroundColor: "transparent"
            }]
        }
        });
    }


    render() {
        return (
             <div classname="chart-section">
                <div classname="chart-body">
                    <canvas ref={this.canvasRef} />
                </div>
            </div>
        ) 
    }
}

export default LineChart;```
biao12319880808 回答:如何在ReactJS中扩展chartjs折线图以同时显示实线和虚线?

可以使用反应-chartjs-2 https://github.com/jerairrest/react-chartjs-2,它实现对反应并且可以称之为像任何常规阵营组件时的选项和数据集就像在chart.js之chart.js之>

本文链接:https://www.f2er.com/2775675.html

大家都在问