gpt4 book ai didi

javascript - 如何更改 amcharts 饼图主题?

转载 作者:行者123 更新时间:2023-12-03 06:34:42 24 4
gpt4 key购买 nike

我的 HTML 代码是这样的:

<div id="chartdiv" style="width: 100%; height: 362px;"></div>

我的Javascript代码是这样的:

var chart;
var legend;

var chartData = [
{
"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
}
];
console.log(chartData);
AmCharts.ready(function () {
// PIE CHART
chart = new AmCharts.AmPieChart();
chart.dataProvider = chartData;
chart.titleField = "country";
chart.valueField = "litres";

// WRITE
chart.write("chartdiv");
});

演示和完整代码如下:https://jsfiddle.net/oscar11/4qdan7k7/2/

我想更改 amchart 主题,如下所示:https://www.amcharts.com/demos/simple-pie-chart/

我添加了 light.js 库,但主题没有改变

有什么办法可以解决我的问题吗?

最佳答案

您需要在初始化时指定theme选项,如下所示,并直接使用makeChart而不是Amcharts.AmPieChart()。您更新后的代码将是:

AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "light",
"dataProvider": chartData,
"valueField": "litres",
"titleField": "country",
"export": {
"enabled": true
}
});

UPDATED FIDDLE

关于javascript - 如何更改 amcharts 饼图主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38280802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com