Amcharts 的新用户(和编程!)并尝试使用他们的示例之一(https://codepen.io/team/amcharts/pen/gOpWroQ), ,但是当我从外部 JSON 文件中提取数据时,它无法正常工作。JSON 结构和格式是正确的,我将数据从 JSON 文件复制到 var data [] 中,并且工作正常。
笔在这里:(https://codepen.io/moneycarlo/pen/zYKdyGz但是我无法托管 json 文件)。
第 10 行是我加载 JSON 数据的位置,但如果我删除 var 数据信息并取消注释第 10 行,结果不会绘制 4 行。相反,它是 1 条线,上面有每个日期的多个堆叠点。
我猜这是预处理器中的东西。我的印象是,当您从 JSON 等外部数据加载时,它会自动分配给 data 属性,并且这些函数的工作方式相同。
我缺少什么?
am4core.useTheme(am4themes_animated);
// Source data
var data = [
{"date":"2019-07-05","domain":"aol.com","hits":"119489"},{"date":"2019-07-05","domain":"gmail.com","hits":"295834"},{"date":"2019-07-05","domain":"hotmail.com","hits":"8000"},{"date":"2019-07-05","domain":"yahoo.com","hits":"324263"},{"date":"2019-07-06","domain":"aol.com","hits":"195042"},{"date":"2019-07-06","domain":"gmail.com","hits":"258402"},{"date":"2019-07-06","domain":"hotmail.com","hits":"100000"},{"date":"2019-07-06","domain":"yahoo.com","hits":"427865"}
];
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
//chart.dataSource.url = "data_1.php";
// Create axes
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.minGridDistance = 30;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
chart.colors.list = [
am4core.color("red"),
am4core.color("blue"),
am4core.color("green")
];
// Create series
function createSeries(field, name, id) {
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "hits";
series.dataFields.dateX = "date";
series.name = name;
series.tooltipText = "{dateX}: [b]{valueY}[/]";
series.strokeWidth = 2;
var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.circle.stroke = am4core.color("#fff");
bullet.circle.strokeWidth = 2;
牧羊人nacy
相关分类