Android堆积条形图 [英] Android Stacked Bars Chart

查看:104
本文介绍了Android堆积条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MPAndroidChart 库,尝试自定义堆积条. 目的是显示两种货币之间的差异. 因此,假设此示例在一月份. 货币1 = 8; 货币#2 = 12

I'm using the MPAndroidChart library, trying to customize the Stacked Bars. The objective is to display the differences between 2 currencies. So suppose this example for January. Currency #1 = 8; Currency #2 = 12

这个想法是在相同的栏中显示两个值,而不是将两个值(8 + 12)相加,以得到值8在前面"和值12在后面". 因此,柱线的总高就是最大值.

The idea is to show in the same bar both values, but instead of sum the 2 values ( 8 + 12) to have the value 8 "in front" and the value 12 "behind". So the total high of the bar is the max value.

我试图这样做,扩展了BarEntry类,而不是计算总和,而是设置最大值.但是我现在只看到一个条形图(值= 12的那个条形图)

I tried to do that, extending the BarEntry class, and instead of calculate the sum, just set the max value. But I'm seeing only one bar now (the one with value = 12)

您知道是否支持这种逻辑吗?有什么建议吗?

Do you know if this kind of logic is supported? Any advice?

推荐答案

查看指南关于如何创建堆叠式条形图,以及按以下方式在堆叠条形图中创建一个条目:

Create an entry in the stacked-bar-chart in the following way:

BarEntry entry = new BarEntry(xValue, new float[] { 8f, 12f });

这将创建一个总高度为20的条目,由两个不同的值(8和12)组成. "xValue"是此栏将在x轴上显示的位置.

This will create an entry with a total height of 20, consisting of two different values (8 and 12). The "xValue" is the position this bar will show up on the x-axis.

您可以根据需要为堆栈(浮点数组)使用尽可能多的条目. 如果打算仅执行单个条目(不进行堆栈),请不要使用采用浮点数组的BarEntry构造函数,而应只采用单个值的构造函数.

You can use as many entries for the stack (float array) as you want. If you intend to do only single entries (no stacks), do not use the BarEntry constructor that takes a float array, use the one that only takes a single value.

这篇关于Android堆积条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆