简体   繁体   English

amCharts 4:加载外部数据时,值的总和不起作用

[英]amCharts 4: sum of values does not work when loading external data

I am loading an external data and values are working on series and tooltips pretty fine but the main value that is the sum is returning " undefined " as your see:我正在加载一个外部数据,并且值在系列和工具提示上工作得很好,但作为总和的主要值正在返回“未定义”,如您所见:

不明确的

Here is the working code chart when I use static data.这是我使用 static 数据时的工作代码图表。 I put // in the dataSource that I am using to load the external data.我把//在我用来加载外部数据的数据源中。

 am4core.useTheme(am4themes_animated); //Theme var chart = am4core.create("chartdiv", am4charts.PieChart); chart.hiddenState.properties.opacity = 0; // Cria o fade-in inicial chart.data = [ { tipo: "Call", value: 347548256.09 }, { tipo: "Put", value: 424644842.25 } ] //chart.dataSource.url = "http://www.stock1.com.br/public/js/datasource/volume_opcoes.json"; chart.language.locale = am4lang_pt_BR; /* chart.numberFormatter.numberFormat = "#a"; chart.numberFormatter.bigNumberPrefixes = [ { "number": 1e+3, "suffix": "K" }, { "number": 1e+6, "suffix": "M" }, { "number": 1e+9, "suffix": "B" } ]; */ chart.radius = am4core.percent(70); chart.innerRadius = am4core.percent(40); chart.startAngle = 180; chart.endAngle = 360; var series = chart.series.push(new am4charts.PieSeries()); series.dataFields.value = "value"; series.dataFields.category = "tipo"; series.slices.template.cornerRadius = 10; series.slices.template.innerCornerRadius = 7; series.slices.template.inert = true; series.slices.template.stroke = new am4core.InterfaceColorSet().getFor("background"); series.slices.template.strokeWidth = 1; series.slices.template.strokeOpacity = 1; series.slices.template.tooltipText = "R$ {value.value}"; series.slices.template.tooltipText.fill = am4core.color("#ffffff"); series.alignLabels = false; series.labels.template.bent = true; series.labels.template.radius = 8; series.labels.template.padding(0,0,0,0); series.labels.template.fill = am4core.color("#475F7B"); series.hiddenState.properties.startAngle = 90; series.hiddenState.properties.endAngle = 90; var label = chart.seriesContainer.createChild(am4core.Label); label.fill = am4core.color("#475F7B"); label.textAlign = "middle"; label.horizontalCenter = "middle"; label.verticalCenter = "middle"; label.adapter.add("text", function(text, target) { return "[bold font-size:18px]" + "R$" + series.dataItem.values.value.sum + "\n" + "[font-size:14px]Volume Total[/]"; });
 <script src="https://cdn.amcharts.com/lib/4/core.js"></script> <script src="https://cdn.amcharts.com/lib/4/charts.js"></script> <script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script> <script src="//www.amcharts.com/lib/4/lang/pt_BR.js"></script> <div id="chartdiv"></div>

Here you see the sum working because I am loading the data right here.在这里您可以看到总和有效,因为我正在这里加载数据。 This snippet doesn't let me use my json.这个片段不允许我使用我的 json。 By the way, the one I am trying to load is: json .顺便说一句,我要加载的是: json

A second problem I am facing is the reduction of large numbers that is not working as it should.我面临的第二个问题是大量减少无法正常工作的情况。 I let commented on the snippet above.我对上面的片段发表了评论。

Does anyone know where I'm going wrong?有谁知道我要去哪里错了?

After a long searching and reading amCharts 4 documentation, here is the answer:经过长时间的搜索和阅读 amCharts 4 文档,答案如下:

The "undefined" was solved by changing the var label and removing the label.adapter.add to:通过更改var label并删除label.adapter.add来解决“未定义”问题:

var label = series.createChild(am4core.Label);
label.text = "[bold font-size:16px]R${values.value.sum}\n[normal]Volume Total";
label.fill = am4core.color("#475F7B");
label.horizontalCenter = "middle";
label.verticalCenter = "bottom";

The second problem, about the Big Numbers, was solved changing the chart.numberFormatter.numberFormat = "#a";第二个问题,关于大数字,通过改变chart.numberFormatter.numberFormat = "#a";得到解决。 to chart.numberFormatter.numberFormat = "#.0a"; to chart.numberFormatter.numberFormat = "#.0a"; . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM