VectorRenderer - Add Color based upon Dataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Fred
Posts: 38
Joined: Sat Dec 12, 2015 4:57 pm
antibot: No, of course not.

VectorRenderer - Add Color based upon Dataset

Post by Fred » Thu Nov 16, 2017 12:21 am

Hello,
First, I've checked the forum as well as evaluated the VectorRenderer's methods.

Issue: Multiple datasets of the same type of VectorSeries (split by an attribute of the data) and want to display
all on the same plot (over-lay). Each dataset will have the same types of series but with varying amounts of data related
to the attribute. I would want the legend to show Dataset name(s) and color. Would build in the functionality
that a user could select a dataset to view from which the other dataset(s) would be made invisible. The related series to that
Dataset (made visible) would then show the series data along with the Legend now reflecting the series names and colors.

I have this working now but only for a single dataset. I have determined that there is no current means within the JFreeChart libraries
unless I've missed something. Sample of the code below.

Code: Select all

XYPlot plot = new XYPlot();
VectorXYDataset datasetAlpha = createDataset("Alpha");
VectorXYDataset datasetBeta = createDataset("Beta");
...
VectorRenderer vr = new VectorRenderer();
...
plot.setDataset(0, datasetAlpha);
plot.setRenderer(0,vr);
plot.setDataset(1, datasetBeta);
plot.setRenderer(1,vr);
..
I believe the plot will render all datasets. Also believe I could identify the dataset to be able to make the related values invisible.
But here's the challenge: I want the various datasets when initially rendered showing 1 color for each dataset with all series
of that dataset the same color. So if there were 3 datasets, each with 5 series, initially the renderer would show only 3
colors of data and the Legend to represent that. With functionality, one could then select a dataset to say make visible
from which the other 2 datasets are made invisible and the 1 dataset made visible would now show the series (by color) to
include the Legend. Hope that makes sense.

The only way I see making this work with whats presently available is to create an additional series in a single dataset where
that additional series (setVisible) defaults to being on with others off to start with. The Legend would reflect that. Functionality
could then be defined similar to what I mentioned above to turn that "dataset" series off and turn on the desired series which would
show a change to the legend and those different color/representations.

If there is a new release being planned perhaps this might have some traction in going forward.

Please advise if this is doable by other means or not based upon what I've laid out above.

Regards,
Fred

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: VectorRenderer - Add Color based upon Dataset

Post by paradoxoff » Sun Nov 19, 2017 9:14 am

I am having trouble to understand your requirements. Is it something like this:
- Intially, you are having multiple datasets (say 3), each with 5 series, and the legend should not reflect the 3*5 series, but only the 3 datasets.
- Once the user selects one dataset, the other datasets shall disappear, and the legend should now show the 5 series of the visible dataset.

Fred
Posts: 38
Joined: Sat Dec 12, 2015 4:57 pm
antibot: No, of course not.

Re: VectorRenderer - Add Color based upon Dataset

Post by Fred » Wed Nov 22, 2017 4:51 pm

Paradoxoff that is correct. Again, I believe the current tools/methods are capable of performing this feat but lots of work in coding it.
Was just trying to see if (a) there was another way or I was going about it work and or (b) there is a plan in place to give this functionality in
the near future and look for it in a coming release.

Have a great Thanksgiving All.

Fred

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: VectorRenderer - Add Color based upon Dataset

Post by paradoxoff » Wed Nov 22, 2017 6:27 pm

Hi Fred,
Personally, I do not believe that a future JFreeChart versions will support your requirements.
If you have some data in what form ever, it is your responsibility to make them available in a form that fulfills the constraints defined by the various dataset implementations of JFreeChart.
You have mentioned have you "split by an attribute of the data". I guess that you have in fact two attributes: initially, the data are split by the first (lets call it "major") attribute, and you get one dataset for each individual value of the major attribute. Each dataset is then splitted by a second attribute (the "minor" attribute), and you get one series for each value of the minor attribute, or better one series for each unique combination of the major and minor attribute. All series of a given dataset should be combined to a single entry in the legend.
After the user has selected one "dataset" (which probably means "one value for the major attribute"), the other datasets should be hidden, and the individual series of the remaining dataset should now all appear in the legend.
Would it be ok, if, before the "dataset selection", the individual series of a given dataset look all the same, i. e. have the same color?
If so, I would proceed as follows:
1. Before the dataset selection, split the data based on the major attribute. Create a VectorXYDataset with one series per individual value of the major attribute.
2. After the dataset selection, split the data based on the minor attribute. Ignore all "data rows" that have the wrong value for the major attribute. Create a VectorXYDataset with one series per individual value of the minor attribute. Replace the dataset created in 1. with the dataset created in 2. The changes in the dataset should be automagically visible.
Last edited by paradoxoff on Wed Nov 22, 2017 8:11 pm, edited 1 time in total.

Fred
Posts: 38
Joined: Sat Dec 12, 2015 4:57 pm
antibot: No, of course not.

Re: VectorRenderer - Add Color based upon Dataset

Post by Fred » Wed Nov 22, 2017 7:33 pm

Thanks Paradoxoff. Already heading in that direction.

Locked