Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

android - MPAndroidChart How to represent multiple dataset object with different number of points in the same chart line

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...