簡體   English   中英

Chartjs-如何更改甜甜圈圖的表示法

[英]Chartjs - how to change the notation of doughnut chart

我使用以下代碼創建了一個甜甜圈圖

  var randomScalingFactor = function() { return Math.round(Math.random() * 100); }; var config = { type: 'doughnut', data: { datasets: [{ data: [ randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), ], backgroundColor: [ window.chartColors.red, window.chartColors.orange, window.chartColors.yellow, window.chartColors.green, window.chartColors.blue, ], label: 'Dataset 1' }], labels: [ "Red", "Orange", "Yellow", "Green", "Blue" ] }, options: { responsive: true } }; window.onload = function() { var ctx = document.getElementById("chart-area").getContext("2d"); window.myPie = new Chart(ctx, config); }; 
 <script src="http://www.chartjs.org/samples/latest/utils.js"></script> <script src="http://www.chartjs.org/dist/2.7.0/Chart.bundle.js"></script> <div id="canvas-holder" style="width:40%"> <canvas id="chart-area" /> </div> 

並顯示如下圖

在此處輸入圖片說明

是否可以像波紋管圖像那樣更改圖形符號? 我試圖檢查文檔,但沒有發現任何更改。 在此處輸入圖片說明

我猜您需要使用onAnimationComplete方法遍歷每個datasetsmetadata以重構工具提示值以使其成為值。

這是一個演示,

https://jsfiddle.net/c8Lk2381/246/

HTML

<canvas id="chart" height="450" width="640"></canvas>

使用Javascript

tooltip.transition(Chart.helpers.easingEffects.linear).draw();
            }, self);
        }, self);
    }
},
    data: {
        datasets: [{
            data: [
                2,
                4,
                7,
                1,
                6,
            ],
            backgroundColor: [
                "Red",
                "Green",
                "Yellow",
                "Grey",
                "Purple",
            ],
        }],
        labels: [
            "Red",
            "Green",
            "Yellow",
            "Grey",
            "Purple"
        ]
    },
};

var ctx = document.getElementById("chart").getContext("2d");
var doughnutchart = new Chart(ctx, doughnutChartConfig);

希望這可以幫助!

暫無
暫無

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

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