我们可以使用下拉菜单更改 amCharts 中的图表类型吗?

问题描述 投票:0回答:1

假设我最初加载了饼图,我希望用户从下拉列表中将其更改为折线图或任何其他类型的图表。我们如何在 amCharts 中实现它?我在 HighCharts 中看到过,但找不到 amCharts 的解决方案。

angular charts highcharts amcharts
1个回答
0
投票

你可能想尝试这样的事情

document
    .getElementById("chartType")
    .addEventListener("change", function () {
      var selectedChartType = document.getElementById("chartType").value;
      changeChartType(selectedChartType);
    });

  // Function to change chart type
  function changeChartType(selectedType) { // the functions should be under if else statement
      if (selectedType === "pie") { //put the pie chart function here}
      else if (selectedType === "line") {//put the line chart function here}
//your data should be like this
series.data.setAll([
        { category: "Category 1", value: 100 },
        { category: "Category 2", value: 200 },
        { category: "Category 3", value: 300 },
        { category: "Category 4", value: 400 },
        { category: "Category 5", value: 500 }
    ]);
© www.soinside.com 2019 - 2024. All rights reserved.