Skip to content
Snippets Groups Projects
Commit 0e3d2338 authored by Tim Molter's avatar Tim Molter
Browse files

Issue #100 and #129 - allow excluding certain series from chart legend

parent a935e914
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ import org.knowm.xchart.internal.style.markers.SeriesMarkers;
* <ul>
* <li>A Line Chart created from multiple category series types
* <li>GGPlot2 Theme
* <li>disabling some series shown in legend
*/
public class LineChart07 implements ExampleChart {
......@@ -97,7 +98,7 @@ public class LineChart07 implements ExampleChart {
for (int i = 0; i < seriesNames.length; i++) {
Series_Category series = chart.addSeries(seriesNames[i], xAxisKeys, Arrays.asList(dataPerSeries[i]));
series.setMarker(SeriesMarkers.NONE);
// series.setChartCategorySeriesRenderStyle(ChartCategorySeriesRenderStyle.Line);
series.setShowInLegend(i % 2 == 0);
}
return chart;
......
......@@ -21,7 +21,7 @@ import java.awt.Color;
import org.knowm.xchart.internal.chartpart.RenderableSeries.LegendRenderType;
/**
* A Series containing X and Y data to be plotted on a Chart
* A Series containing data to be plotted on a Chart
*
* @author timmolter
*/
......@@ -29,11 +29,12 @@ public abstract class Series {
public abstract LegendRenderType getLegendRenderType();
private String name = "";
private final String name;
/** Fill Color */
private Color fillColor;
private boolean showInLegend;
/**
* Constructor
*
......@@ -46,7 +47,6 @@ public abstract class Series {
throw new IllegalArgumentException("Series name cannot be null or zero-length!!!");
}
this.name = name;
}
public Color getFillColor() {
......@@ -64,4 +64,14 @@ public abstract class Series {
return name;
}
public boolean isShowInLegend() {
return showInLegend;
}
public void setShowInLegend(boolean showInLegend) {
this.showInLegend = showInLegend;
}
}
......@@ -72,7 +72,7 @@ public abstract class Legend_<ST extends Styler, S extends Series> implements Ch
// We call get bounds hint because sometimes the Axis object needs it to know it's bounds (if Legend is outside Plot). If it's null, we just need to calulate it before painting, because the paint
// methods needs the bounds.
if (bounds == null) { // No other part asked for the bounds yet. Probably because it's an "inside" legend location
bounds = getBoundsHint(); // Actually, the only information contained in thsi bounds is the width and height.
bounds = getBoundsHint(); // Actually, the only information contained in this bounds is the width and height.
}
// legend draw position
......@@ -136,6 +136,10 @@ public abstract class Legend_<ST extends Styler, S extends Series> implements Ch
Map<String, S> map = chart.getSeriesMap();
for (Series series : map.values()) {
if (series.isShowInLegend()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
double legendEntryHeight = 0; // could be multi-line
......
......@@ -69,6 +69,10 @@ public class Legend_AxesChart<ST extends Styler_AxesChart, S extends Series> ext
Map<String, Series_AxesChart> map = chart.getSeriesMap();
for (Series_AxesChart series : map.values()) {
if (series.isShowInLegend()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
float legendEntryHeight = 0;
......
......@@ -66,6 +66,10 @@ public class Legend_Pie<ST extends Styler_AxesChart, S extends Series> extends L
Map<String, Series> map = chart.getSeriesMap();
for (Series series : map.values()) {
if (series.isShowInLegend()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
float legendEntryHeight = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment