1

I've been searching for an answer for this but since i couldn't find any, i'll post the question.

I have a plot drawn, with a list below showing some data, one of the parameters of each row is drawn in the plot.

I'm trying to change the color of the point when the user clicks in one of the views of the list, to reflect in the plot that the row matches the point, but i haven't been able to replicate it.

There is any way to get an specific point of the graph, to change its color?

Thanks in advance.

1 Answers1

0

I don't know if what you are trying to do is possible but you can try to add a serie to your plot containing the point that you want to highlight when user clicks. When a new click is done you just need to remove the added serie and add a new one containing the new point.

The added serie must have a different style so you can see the "changed color" and must be the last added serie so it will be in forground.

Hope it helps


Edit

What you can do to adapt it to your use case is to extend a XYPlot class, create a SeriesType highlightedPoint property and add a method like (not tested) :

public void highlightPoint(Number x, Number y, FormatterType formatter){
    // if there is already a highlighted point we remove it (we want to highlight just one point)
    if(highlightedPoint != null) {
        removeSeries(highlightedPoint);
        highlightedPoint = null;
    }

    // we need to highlight the new point, which means adding a serie on top of the others
    highlightedPoint = new SimpleXYSeries("Highlighted Point");
    highlightedPoint.addFirst(x,y);
    addSeries(highlightedPoint, formatter);
}

You just need to call this method on your plot instance each time user clicks on your list.

Community
  • 1
  • 1
Kalem
  • 1,132
  • 12
  • 33
  • Worked like a charm as a workaround, but it'd be nice to have the possibility of picking a point from the plot and changing its color, thanks! – Rafael González Oct 08 '15 at 09:06
  • I kinda agree with you but i think it's not that easy and straitforward when you have mutiple series in one plot. – Kalem Oct 08 '15 at 09:34
  • Well i didn't take a look into the library inner code but if you have all the XYSeries inside a List/Map you could access one of them and then manipulate that XYSeries itself – Rafael González Oct 08 '15 at 14:29
  • You don't need to look at the lib code to extend a class. I just gave you an example of the implementation you can use to make your functionality easier to use. If you have a working implementation that feets your needs that's good for me :) – Kalem Oct 08 '15 at 14:37
  • Yeah i already completed the implementation when i saw your first response, my comment was just a suggestion for a future update of the library itself. Thanks! – Rafael González Oct 08 '15 at 15:13