1

我使用带有 React 的 Chartjs 2 成功地绘制了一堆数据点,并带有一个类别 Y 轴,但想用它们的类别标签来标记它们。他们目前将“未定义”显示为工具提示值:

在此处输入图像描述

这是我现在所拥有的(不工作):

labels: this.state.graphData.eventWeekArray,
datasets: [
     {
            label: title,
            labels: data,
            fill: false,
            lineTension: 0.1,
            borderColor: colorArray()[counter],
            borderCapStyle: 'butt',
            borderJoinStyle: 'miter',
            pointBorderColor: 'rgba(75,192,192,1)',
            pointBackgroundColor: '#fff',
            pointBorderWidth: 1,
            pointHoverRadius: 6,
            pointHoverBackgroundColor: 'rgba(75,192,192,1)',
            pointHoverBorderColor: 'rgba(220,220,220,1)',
            pointHoverBorderWidth: 3,
            pointRadius: 1,
            pointHitRadius: 1,
            showLine: true,
            steppedLine: true,
            spanGaps: true,
            data: data,
            year: dataYear,
            measurement: 'state'
        }
]

使用选项和 scaleLabel 也不起作用:

const options = {
        legend: {
            display: true
        },
        scales: {
            xAxes: [
                {
                    scaleLabel: {
                        display: true,
                        labelString: 'Weeks'
                    },
                    ticks: {
                        autoSkip: true,
                        autoSkipPadding: 20
                    }
                }
            ],
            yAxes: [
                {
                    type: 'category',
                    labels: this.state.eventLabelArray
                },
                {
                    type: 'linear',
                    labels: this.state.brixLabelArray
                }
            ]
        }
    };
4

0 回答 0