XYBlockRenderer: change color of items

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

XYBlockRenderer: change color of items

Post by ekta1994 » Fri May 12, 2017 8:18 am

I am using XYBlockRenderer for XYZ dataset having items. Color of every item is a function of its z value. I am using paintscale to assign the color. Now, I want to change the color of any particular item, lets say 9'th on mouse over. But this should change color of only 9'th item number of the dataset and others should remain the same. On detecting the mouse over I call

Code: Select all

notifyListeners(new RenderChangeEvent(this))
function which fires the renderer change event and calls

Code: Select all

getPaint(double)
function of paintscale. How can this function be overridden to return a different color as it accepts only the double (z-value) of the item number.
I tried maintaining a flag which I set on mouse over. In

Code: Select all

getPaint()
, I check if the flag is set, I return a different color. But this changes the color of all data items.
Any help will be appreciated.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: XYBlockRenderer: change color of items

Post by John Matthews » Fri May 12, 2017 9:22 am

You can return the desired color for a particular value from your implementation of PaintScale::getPaint. A complete example is cited here.

ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

Re: XYBlockRenderer: change color of items

Post by ekta1994 » Fri May 12, 2017 9:30 am

Yes, I can return the desired color. I am currently also doing the same but how to modify the color for a particular item of XYZ dataset. On mouse over, I want color of only one particular item to be changed. getPaint() distinguishes color using the z-value, not on the basis of item number. That is, if i hovered on 9th data item having 5 as the z-value, all other data items which have 5 z-value will also change their color. I don't want this.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: XYBlockRenderer: change color of items

Post by John Matthews » Fri May 12, 2017 11:06 am

In the XYItemEntity reported to your ChartMouseListener, change the z value of the corresponding XYZDataset element to some sentinel value that is unique in your PaintScale.

ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

Re: XYBlockRenderer: change color of items

Post by ekta1994 » Fri May 12, 2017 5:25 pm

Changing z-value and then adding notifylistener calls the getPaint() for every dataset item i.e. whole repaint is happening. Shoudn't there be an easier method for this?
Also, why doesn't XYZDataset provide setZValue(int series, int item) when it provides getZValue(int series, int item) ?

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: XYBlockRenderer: change color of items

Post by John Matthews » Sat May 13, 2017 12:52 am

Yes, performance is a limiting factor for large datasets and slow targets. You might look at resampling; I've used ImageJ, among others.

Locked