markdown amCharts V4:带Legend的简单饼图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown amCharts V4:带Legend的简单饼图相关的知识,希望对你有一定的参考价值。

@import url("https://fonts.googleapis.com/css?family=Archivo+Narrow");

body {
  font-family: "Archivo Narrow";
}

#chartdiv {
  width: 100%;
  height: 400px;
}
/**
 * --------------------------------------------------------
 * This demo was created using amCharts V4 preview release.
 * 
 * V4 is the latest installement in amCharts data viz
 * library family, to be released in the first half of
 * 2018.
 *
 * For more information and documentation visit:
 * https://www.amcharts.com/docs/v4/
 * --------------------------------------------------------
 */

// Create chart instance
var chart = amcharts4.create("chartdiv", amcharts4.pie.PieChart);

// Add data
chart.data = [{
  "country": "Lithuania",
  "litres": 501.9
}, {
  "country": "Czech Republic",
  "litres": 301.9
}, {
  "country": "Ireland",
  "litres": 201.1
}, {
  "country": "Germany",
  "litres": 165.8
}, {
  "country": "Australia",
  "litres": 139.9
}, {
  "country": "Austria",
  "litres": 128.3
}, {
  "country": "UK",
  "litres": 99
}, {
  "country": "Belgium",
  "litres": 60
}, {
  "country": "The Netherlands",
  "litres": 50
}];

// Add and configure Series
var pieSeries = chart.series.push(new amcharts4.pie.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";

// Let's cut a hole in our Pie chart the size of 40% the radius
chart.innerRadius = amcharts4.percent(40);

// Put a thick white border around each Slice
pieSeries.slices.template.stroke = amcharts4.color("#4a2abb");
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;


// Add a legend
chart.legend = new amcharts4.pie.Legend();
<script src="https://www.amcharts.com/lib/4/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/4/pie.js"></script>
<div id="chartdiv"></div>
amCharts V4:  Simple Pie chart with Legend
------------------------------------------


A [Pen](https://codepen.io/harunpehlivan/pen/xWBXYg) by [HARUN PEHLİVAN](https://codepen.io/harunpehlivan) on [CodePen](https://codepen.io).

[License](https://codepen.io/harunpehlivan/pen/xWBXYg/license).

以上是关于markdown amCharts V4:带Legend的简单饼图的主要内容,如果未能解决你的问题,请参考以下文章

markdown amCharts V4:可变高度3D饼图

markdown amCharts V4:堆积柱形图

markdown amCharts V4:嵌套饼图

markdown amCharts V4:垂直Sankey图

markdown amCharts V4:雷达时间线图

markdown amCharts V4:雷达时间线图