How to change amcharts pie themes?

帅比萌擦擦* 提交于 2019-11-27 04:08:02

问题


My HTML code is like this :

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

My Javascript code is like this :

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");
});

Demo and complete code is like this : https://jsfiddle.net/oscar11/4qdan7k7/2/

I want to change amchart themes like this : https://www.amcharts.com/demos/simple-pie-chart/

I add light.js library, but the themes not change

Any solution to solve my problem?


回答1:


You need to specify the theme option while initializing as below and also make use of makeChart directly instead of Amcharts.AmPieChart(). Your updated code would be:

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

UPDATED FIDDLE



来源:https://stackoverflow.com/questions/38280802/how-to-change-amcharts-pie-themes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!