英文:
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<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);
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论