简体   繁体   中英

Resize the radius with in ChartJs Chart

在此处输入图片说明

Im using ChartJs for "doughnut-pie-chart". The default radius is much bigger than what I expect,. Is there and way to resize the radius width.?

The documentatin part did not provide any info.

  $( document ).ready(function() {
    var ctx = document.getElementById("chart-area").getContext("2d");

    new Chart(ctx).Doughnut(doughnutData, {responsive : true});
  });

Extend the Doughnut chart to set the outerRadius (perhaps using an option that you pass in) after the prototype's initialization

Chart.types.Doughnut.extend({
    name: "DoughnutAlt",
    initialize: function(data){
        Chart.types.Doughnut.prototype.initialize.apply(this, arguments);
        this.outerRadius *= this.options.radiusPercentage;
    }
});

and then use the extended chart type

var ctx = document.getElementById("chart-area").getContext("2d");
var myNewChart = new Chart(ctx).DoughnutAlt(doughnutData, {
    responsive : true,
    radiusPercentage: 0.8
});     

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM