安卓 AnyChart 中的柱状图显示单个项目的两个垂直条。

huangapple go评论81阅读模式
英文:

Android Anychart Cartesian showing 2 vertical bars for a single item

问题

使用安卓的AnyChart库来绘制直角坐标系,使用我提供的数据。然而,每个项目的直角坐标系出现了两个垂直的条形,而不是只有一个条形(就像在图像中为产品“Pe”所示)。我提供的图像更好地显示了我试图解释的内容。以下是代码部分:

Cartesian cartesian = AnyChart.column();
List<DataEntry> dataEntries = new ArrayList<>();
dataEntries.add(new ValueDataEntry("Tr", 10));
dataEntries.add(new ValueDataEntry("Fo", 20));
dataEntries.add(new ValueDataEntry("Ho", 30));
dataEntries.add(new ValueDataEntry("En", 40));
dataEntries.add(new ValueDataEntry("Ed", 50));
dataEntries.add(new ValueDataEntry("Ch", 60));
dataEntries.add(new ValueDataEntry("Ap", 70));
dataEntries.add(new ValueDataEntry("He", 80));
dataEntries.add(new ValueDataEntry("Pe", 90));
dataEntries.add(new ValueDataEntry("Ot", 10));
cartesian.data(dataEntries);
cartesian.title("Team Possession");

Column column = cartesian.column(dataEntries);

column.tooltip()
        .titleFormat("{%X}")
        .position(Position.CENTER_BOTTOM)
        .anchor(Anchor.CENTER_BOTTOM)
        .offsetX(0d)
        .offsetY(5d)
        .format("${%Value}{groupsSeparator: }");

cartesian.animation(true);
cartesian.title("Top 10 Cosmetic Products by Revenue");

cartesian.yScale().minimum(0d);

cartesian.yAxis(0).labels().format("${%Value}{groupsSeparator: }");

cartesian.tooltip().positionMode(TooltipPositionMode.POINT);
cartesian.interactivity().hoverMode(HoverMode.BY_X);

cartesian.xAxis(0).title("Product");
cartesian.yAxis(0).title("Revenue");
anyChartView.setChart(cartesian);

如何使其只显示一个条形?

英文:

Am using the android anychart library to draw a cartesian using the data i have provided. However, the cartesian appears with 2 vertical bars for each item instead of only one bar (Like indicated for the product "Pe" in the Image).. The Image I have provided gives a better display of what I am trying to explain. This is the code.. I have already innitialized the anychartview in oncreate.

Cartesian cartesian = AnyChart.column();
List&lt;DataEntry&gt; dataEntries = new ArrayList&lt;&gt;();
dataEntries.add(new ValueDataEntry(&quot;Tr&quot;, 10));
dataEntries.add(new ValueDataEntry(&quot;Fo&quot;, 20));
dataEntries.add(new ValueDataEntry(&quot;Ho&quot;, 30));
dataEntries.add(new ValueDataEntry(&quot;En&quot;, 40));
dataEntries.add(new ValueDataEntry(&quot;Ed&quot;, 50));
dataEntries.add(new ValueDataEntry(&quot;Ch&quot;, 60));
dataEntries.add(new ValueDataEntry(&quot;Ap&quot;, 70));
dataEntries.add(new ValueDataEntry(&quot;He&quot;, 80));
dataEntries.add(new ValueDataEntry(&quot;Pe&quot;, 90));
dataEntries.add(new ValueDataEntry(&quot;Ot&quot;, 10));
cartesian.data(dataEntries);
cartesian.title(&quot;Team Possession&quot;);
Column column = cartesian.column(dataEntries);
column.tooltip()
.titleFormat(&quot;{%X}&quot;)
.position(Position.CENTER_BOTTOM)
.anchor(Anchor.CENTER_BOTTOM)
.offsetX(0d)
.offsetY(5d)
.format(&quot;${%Value}{groupsSeparator: }&quot;);
cartesian.animation(true);
cartesian.title(&quot;Top 10 Cosmetic Products by Revenue&quot;);
cartesian.yScale().minimum(0d);
cartesian.yAxis(0).labels().format(&quot;${%Value}{groupsSeparator: }&quot;);
cartesian.tooltip().positionMode(TooltipPositionMode.POINT);
cartesian.interactivity().hoverMode(HoverMode.BY_X);
cartesian.xAxis(0).title(&quot;Product&quot;);
cartesian.yAxis(0).title(&quot;Revenue&quot;);
anyChartView.setChart(cartesian);

How can I make it to appear only one bar?
安卓 AnyChart 中的柱状图显示单个项目的两个垂直条。

答案1

得分: 1

因为您对数据应用了两次,并且图表分别创建了两个系列,所以会出现这种情况。
在下面的代码行中,您对图表应用了数据。它会自动根据数据创建一个默认系列。

cartesian.data(dataEntries);

然后,您手动创建了一个系列。这会创建第二个系列。

Column column = cartesian.column(dataEntries);

为了解决这个问题,您可以从代码中删除 cartesian.data(dataEntries); 这一行。

英文:

It happens because you apply data twice and the chart creates two series respectively.
In the line below you apply data to the chart. It automatically create a default series based on the data.

cartesian.data(dataEntries);

Then you create a series manually. It creates the second series.

Column column = cartesian.column(dataEntries);

To solve that you can remove cartesian.data(dataEntries); line from your code.

huangapple
  • 本文由 发表于 2020年10月14日 16:48:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/64349725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定