[英]Is there a way I can get the Bar Width in px/dp's of an MP Android BarChart?
I want to create a "table" (which is build with a recycle view) below my chart.我想在图表下方创建一个“表格”(使用回收视图构建)。 But I want the RecycleView to have the same number of elements of my chart (In this case 7) Is there a way to get the column width
of the Bar Chart
so I can assign the same width to my Recycle View Cells?但我希望 RecycleView 具有相同数量的图表元素(在本例中为 7)有没有办法获取Bar Chart
的列width
,以便我可以为我的回收视图单元格分配相同的宽度?
At the end (if it is posible) I want the two scroll to be synced.最后(如果可能的话)我希望两个滚动同步。
The bar width in pixels is the difference between the value bar width x position (wp) and the label starting position (xp):以像素为单位的条宽是条宽 x 位置 (wp) 与标签起始位置 (xp) 之间的差值:
Transformer transformer = bChart.getTransformer(YAxis.AxisDependency.LEFT);
float bw = (float) transformer.getPixelForValues(bChart.getBarData().getBarWidth(), 0).x;
float xp = (float) transformer.getPixelForValues(0, 0).x;
float barWidthInPixels = bw - xp;
As you can see from the javadoc, BarData#getBarWidth()
returns a the bar width in chart values (not in pixels). 从javadoc可以看出, BarData#getBarWidth()
以图表值(不是以像素为单位)返回条形宽度。
You can translate between chart values (x and y values on the chart) and pixel values (for the Android handset's screen) using a Transformer
. 您可以使用Transformer
在图表值(图表上的x和y值)和像素值(针对Android手机的屏幕)之间进行Transformer
。 Something like the following: 类似于以下内容:
float barWidth = barData.getBarWidth();
Transformer transformer = mChart.getViewPortHandler().getTransformer(AxisDependency.LEFT);
MPPointD barDimensPoint = transformer.getPixelForValues(barWidth, 0);
float barWidthInPixels = (float) barDimensPoint.x;
It's essentially the opposite operation from this question where the requirement is to translate pixels into values on the chart. 它本质上是与这个问题相反的操作,其中要求是将像素转换为图表上的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.