欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

饼状图(pie chart)

程序员文章站 2022-05-26 21:39:26
...

饼状图


更多有趣示例 尽在 小红砖社区

示例

饼状图(pie chart)

代码

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js">
<script src="https://code.highcharts.com/modules/accessibility.js"></script></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

CSS

#container {
	min-width: 310px;
	max-width: 800px;
	height: 400px;
	margin: 0 auto
}

JS

Highcharts.setOptions({
  colors: ['#C0C0C0', '#808080', '#0C090A']
});  
Highcharts.chart('container', {
    chart: {
      plotBackgroundColor: null,
      plotBorderWidth: null,
      plotShadow: false,
      type: 'pie'
    },
    title: {
      text: 'Air Composition'
    },
    tooltip: {
      pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
      pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
          enabled: false
        },
        showInLegend: true
      }
    },
    series: [{
      name: 'Composition',
      colorByPoint: true,
      data: [{
        name: 'Nitrogen',
        //color: '#01BAF2',
        y: 78,
      }, {
        name: 'Oxygen',
        //color: '#71BF45',
        y: 20.9,
        sliced: true,
        selected: true
      }, {
        name: 'Other gases',
        //color: '#FAA74B',
        y: 1.1
      }]
    }]
  });