簡體   English   中英

如何在Chart.js的中心放置單個數據?

[英]How can I place single data on the center in Chart.js?

我的代碼:

        var chart = new Chart('graph_data', {
            type: 'line',
            data: {
                labels: data.labels.labels,
                datasets: dataSets
            },
            options: {
                responsive: true,
                tooltips: {
                    mode: 'index',
                    intersect: false,
                },
                legend: {
                   display: true,
                },
                scales: {
                    xAxes: [{
                        display: true,
                        ticks: {
                            autoSkip: true,
                            maxRotation: 0,
                        },
                        scaleLabel: {
                            display: true,
                            labelString: attributeLabels[data.labels.type],
                        }
                    }],
                    yAxes: [{
                        display: true,
                    }]
                }
            }
        });

當數據很多時,一切都很好。 在此處輸入圖片說明

但是,當有少量數據時,這些點將向左移動。 如何將其放在中心? 不知道? 在此處輸入圖片說明

好吧,我在其他地方解決了這個問題。 如果是單個數據,則將不帶標題的空值添加到數據數組:

datapoints = [NaN, 1800, NaN];
labels = ['', 'Label', ''],

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM