简体   繁体   English

AndroidPlot:添加和删除XYSeries

[英]AndroidPlot: Adding and Removing XYSeries

I'm having a problem with this implementation: 我对此实现有疑问:

       if(blueActive) {
            blueFormat = new LineAndPointFormatter(Color.rgb(0,0,255), null, null);
            blue = new SimpleXYSeries(xArray,yArray, selectedDate);
            Log.e(TAG , "blueActive");
            cvPlot.addSeries(blue, blueFormat);
        }
        if(redActive) {
            redFormat = new LineAndPointFormatter(Color.rgb(255,0,0), null, null);
            red = new SimpleXYSeries(xArray,yArray, selectedDate);
            Log.e(TAG , "redActive");
            cvPlot.addSeries(red, redFormat);
        }
        if(greenActive) {
            greenFormat = new LineAndPointFormatter(Color.rgb(0,255,0), null, null);
            green = new SimpleXYSeries(xArray,yArray, selectedDate);
            Log.e(TAG , "greenActive");
            cvPlot.addSeries(green, greenFormat);
        }

        cvPlot.redraw();

The series are plotted with the correct xArray and yArray, but when the graph redraws, all the plots are the same color. 用正确的xArray和yArray绘制该系列,但是当图形重绘时,所有图都是相同的颜色。 I'm looking for this code to redraw the plot with three different colors. 我正在寻找此代码以三种不同的颜色重新绘制绘图。 Am I doing something logically wrong here? 我在这里在逻辑上做错了吗?

Although this question wasn't very descriptive with the other code involved, ultimately the answer was to add this into the onClick that started the process of adding the plots: 尽管这个问题对所涉及的其他代码不是很描述,但是最终的答案是将其添加到开始添加绘图的onClick中:

xArray.clear(); xArray.clear(); yArray.clear(); yArray.clear();

The lines were overlapping, and when the next color was added, since the red plot was selected after blue, the two arrays grew to include the points of the blue and red, making it look like the color wasn't changing. 线是重叠的,并且当添加下一个颜色时,由于在蓝色之后选择了红色图,所以两个数组逐渐增加以包括蓝色和红色的点,从而使颜色看起来没有变化。 In other words, the red array included the blue array, and since those points were identical to the blue plot, I couldn't see the blue plot since the red plot was on top! 换句话说,红色阵列包括蓝色阵列,并且由于这些点与蓝色曲线相同,因此由于红色曲线位于顶部,所以我看不到蓝色曲线!

I had set up a Log.d long before this problem but really didn't notice the array doubling since I didn't log the count because I only wanted to see that the x and y values were populating. 我早在出现此问题之前就设置了Log.d,但实际上并没有注意到数组加倍,因为我没有记录计数,因为我只想看到x和y值正在填充。

Log your array counts and clear your arrays rook dawg!! 记录您的数组计数并清除您的数组rook dawg !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM