本文介绍了MPAndroidChart如何重新present多个数据集对象在同一图表行不同数量的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MPAndroidChart的图表。我建有多个数据集对象的折线图。

从由MPAndroidChart提供的示例我可以观察到多个数据集的对象可以用相同的线图,但与点(y值)和参照相同x值的那些y值相同数量的绘制。如果我想在同一个折线图用不同的编号引用不同的x值的每一个点(y值)中绘制多个数据集对象,会发生什么?我怎样才能摆脱呢?我能不能够做到这一点。

例如:

  Dataset对象1 Y值:0,12,23,34,50,100,130
                 的X的值:0,10,15,20,25,30,35

数据集对象2 Y值:1,5,10,15,20,30,40,70,75,80
                 的X的值:0,1,2,3,4,5,6,7,8,9
 

解决方案

解决的办法很简单。

创建x值阵列范围从0到36:

 的ArrayList<字符串> xvals =新的ArrayList<字符串>();

的for(int i = 0; I< = 35;我++){
   xvals.add(标签+ I);
}

//创建您的条目...

//添加数据...
 

在这样您可以显示使用X-指数从0到35项。请确保您设置了正确的X指数要显示的每个条目。

I am using MPAndroidChart for charting. I am building a line chart which has multiple dataset objects.

From the examples provided by MPAndroidChart I can observe that multiple dataset objects can be drawn in the same line chart but with the same number of points (y-values) and those y-values referenced to the same x-values. What happens if I want to draw multiple dataset objects in the same line chart with different number of points (y-values) referenced to different x-values for each one? How can I get rid of this? I cannot be able to do it.

For example:

Dataset object 1 Y-values: 0, 12, 23, 34, 50, 100, 130
                 X-values: 0, 10, 15, 20, 25,  30,  35

Dataset object 2 Y-values: 1,  5, 10, 15, 20,  30,  40,  70, 75, 80
                 X-values: 0,  1,  2,  3,  4,   5,   6,   7,  8,  9
解决方案

The solution is simple.

Create an x-values array ranging from 0 to 36:

ArrayList<String> xvals = new ArrayList<String>();

for(int i = 0; i <= 35; i++) {
   xvals.add("Label"+i);
}

// create your entries...

// add the data...

In that way you can display entries with x-indices ranging from 0 to 35.Make sure you set the correct x-index for each entry you want to display.

这篇关于MPAndroidChart如何重新present多个数据集对象在同一图表行不同数量的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:10