HTML5 Canvas pie chart

前端 未结 4 1129
名媛妹妹
名媛妹妹 2020-12-05 07:30

I\'m attempting to create a simple pie chart like shown in the graphic below:

\"enter<

4条回答
  •  一向
    一向 (楼主)
    2020-12-05 07:56

    Here is a pie chart without using external libraries, using html5 canvas :

    See the code

    But it's better to use libraries for drawing charts. in apex-charts there is an option called sparkline, which helps you to remove the extra stuffs and draw a minimal and clean chart.

    Here is a clean donut chart using apex-charts library. (Extra stuffs are removed with sparkline option):

    var options = {
      series: [620, 40],
      labels: ['Finished', 'Unfinished'],
      chart: {
        type: 'donut',
        sparkline: {
          enabled: true,
        }
      },
      plotOptions: {
        pie: {
          donut: {
            labels: {
              show: true,
              total: {
                showAlways: false,
                show: true,
                label: 'Total'
              }
            }
          }
        }
      },
    };
    var chart = new ApexCharts(document.querySelector("#chart"), options);
    chart.render();
    
    

    See it on codepen

提交回复
热议问题