假设我最初加载了饼图,我希望用户从下拉列表中将其更改为折线图或任何其他类型的图表。我们如何在 amCharts 中实现它?我在 HighCharts 中看到过,但找不到 amCharts 的解决方案。
你可能想尝试这样的事情
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 }
]);