我找不到将饼图中的数据导出到CSV或XLSX的方法。我从amCharts.js中检查了此link,但我可以设法使其适应我的需要。
这是我的代码:
function getDataProviderForEventsByFlow(){
$.ajax({
url: restURI,
success: function(data) {
am4core.useTheme(am4themes_kelly);
chartEventsByFLow = am4core.create("events-by-flow", am4charts.PieChart);
chartEventsByFLow.hiddenState.properties.opacity = 0;
chartEventsByFLow.legend = new am4charts.Legend();
var marker = chartEventsByFLow.legend.markers.template.children.getIndex(0);
marker.cornerRadius(12, 12, 12, 12);
marker.strokeWidth = 2;
marker.strokeOpacity = 1;
marker.stroke = am4core.color("#ccc");
chartEventsByFLow.data = data;
var series = chartEventsByFLow.series.push(new am4charts.PieSeries());
series.dataFields.value = "number";
series.dataFields.category = "category";
series.dataFields.color = "color";
series.labels.template.disabled = true;
series.ticks.template.disabled = true;
series.slices.template.tooltipText = "";
}
});
}
和导出功能:
function exportCSVbyFlow() {
chartEventsByFLow.export.toCSV({}, function(data) {
this.download(data, this.defaults.formats.CSV.mimeType, "exportCSVvolumetryByFlow.csv");
});
}
function exportXLSXbyFlow() {
chartEventsByFLow.export.toXLSX({}, function(data) {
this.download(data, this.defaults.formats.XLSX.mimeType, "exportXLSXvolumetryByFlow.xlsx");
});
}
这是控制台中的输出:
无法读取未定义的属性“ toCSV”
无法读取未定义的属性“ toXLSX”
谢谢!
答案 0 :(得分:1)
您提供的代码使用的是v4,但是您尝试使用的示例链接使用的是v3。
您看过this page吗?它显示了一种将菜单添加到具有不同导出选项的图表的方法。它还讨论了使用类似以下代码的程序化导出:
chart.exporting.export("csv");