Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set user-defined legends of PiePlot? #155

Open
farleylai opened this issue Dec 5, 2016 · 2 comments
Open

How to set user-defined legends of PiePlot? #155

farleylai opened this issue Dec 5, 2016 · 2 comments
Assignees
Labels

Comments

@farleylai
Copy link

The legends of a PiePlot seem to use the values by default. It is not a problem with XYPlot which uses the names of DataSeries as legends but how about PiePlot? Is it possible to set the legends with user-defined strings?

256_2048-s-a-r-a-energy-pie eps

@seifertm
Copy link
Collaborator

seifertm commented Dec 6, 2016

There are two types of legends in GRAL. XYPlot uses the SeriesLegend by default, which shows an item in the legend for each data series. PiePlot uses ValueLegend, which displays a legend item per value/row in the data series.

ValueLegend does have a possibility to set arbitrary Strings as labels using ValueLegend.setLabelColumn. This denotes the column index of the plot's DataSource where the respective labels are stored.

In your case you would need to create a DataSource with a Double column and a String column and set the label column to the index of the String column:
ValueLegend piePlotLegend = (ValueLegend) piePlot.getLegend();
piePlotLegend.setLabelColumn(1);

The cast is kind of ugly, but it should do the trick.

@seifertm seifertm self-assigned this Dec 6, 2016
@farleylai
Copy link
Author

farleylai commented Dec 7, 2016

Thanks, it works like a charm.

256_2048-s-n-n-a-energy-pie eps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants