JFreeChart - Legend control with adding different series

J

jc_usernet

Hello.
I am working with JFreeChart (1.0.13) and wish to modify the manner
the legend displays entries for the multiple XY time series.
I want to display 2 series on the graph with one entry into the
legend. The example is grouping a Max and a Min series which gives a
graph above and below an Avg series. As such I want them displayed
together under the name of "Max&Min".
My current code is;
--------------------
this.plot.setDataset( dataset_Index,
createDataset(dataset_DBColumnName) );
this.plot.setRenderer( dataset_Index, dataset_Renderer );

where plot is a class XYPlot
--------------------
I have tried setting the display name in the legend (which comes from
dataset_DBColumnName) - the name of the generated series ) to null
and "" without success.
The first gives a run time error while the second makes a legend entry
with the "" string.

Is there a way I can control this legend entries while I create events
loading in these different series into the Dataset?
A possible work around (which I have not tried) is concatenation the 2
series (Min and Max) together, but a fly back line might occur (most
likely).

Regards JC.....
 
J

John B. Matthews

jc_usernet said:
I am working with JFreeChart (1.0.13) and wish to modify the manner
the legend displays entries for the multiple XY time series. I want
to display 2 series on the graph with one entry into the legend. The
example is grouping a Max and a Min series which gives a graph above
and below an Avg series. As such I want them displayed together
under the name of "Max&Min".
My current code is;
--------------------
this.plot.setDataset( dataset_Index,
createDataset(dataset_DBColumnName) );
this.plot.setRenderer( dataset_Index, dataset_Renderer );

where plot is a class XYPlot
--------------------
I have tried setting the display name in the legend (which comes from
dataset_DBColumnName) - the name of the generated series ) to null
and "" without success. The first gives a run time error while the
second makes a legend entry with the "" string.

Is there a way I can control this legend entries while I create
events loading in these different series into the Dataset? A possible
work around (which I have not tried) is concatenation the 2 series
(Min and Max) together, but a fly back line might occur (most
likely).


I've never combined legend items this way; I'd argue against it. Of
course, you can always add another legend:

LegendItemSource lis = new LegendItemSource() {
LegendItem li = new LegendItem("Min&Max");
LegendItemCollection lic = new LegendItemCollection();
{ lic.add(li); }
public LegendItemCollection getLegendItems() {
return lic;
}
};
chart.addLegend(new LegendTitle(lis));


<http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/LegendItem.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top