在this饼图中,切片的颜色如何更改为所需的渐变颜色而又不失去那种出色的渐变效果。我使用amcharts
这个JavaScript
库来创建图表。
在code中,每个切片颜色都是自动生成的。
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.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 am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.innerRadius = am4core.percent(50);
pieSeries.ticks.template.disabled = true;
pieSeries.labels.template.disabled = true;
let rgm = new am4core.RadialGradientModifier();
rgm.brightnesses.push(-0.8, -0.8, -0.5, 0, - 0.5);
pieSeries.slices.template.fillModifier = rgm;
pieSeries.slices.template.strokeModifier = rgm;
pieSeries.slices.template.strokeOpacity = 0.4;
pieSeries.slices.template.strokeWidth = 0;
chart.legend = new am4charts.Legend();
chart.legend.position = "right";
</script>
<!-- HTML -->
<div id="chartdiv"></div>
答案 0 :(得分:1)
amcharts使用预定义的颜色集来设置图表样式。您可以通过不同的方式自定义该颜色集:
pieSeries.colors.list = [
am4core.color("#845EC2"),
am4core.color("#D65DB1"),
am4core.color("#FF6F91"),
am4core.color("#FF9671"),
am4core.color("#FFC75F"),
am4core.color("#F9F871")
];
pieSeries.slices.template.propertyFields.fill = "color";
pieSeries.slices.template.propertyFields.stroke = "color";
此外,您可以添加渐变以设置图表样式。
Here,您可以找到更多有关amcharts中颜色和渐变的文档。