Improved appearance plot

This commit is contained in:
Sibo Van Gool 2021-07-09 03:57:27 +02:00
parent dcacc40d88
commit 2f2a3a4272

View File

@ -36,7 +36,7 @@ import org.jfree.chart.LegendItemSource;
import org.jfree.chart.annotations.XYImageAnnotation; import org.jfree.chart.annotations.XYImageAnnotation;
import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.block.LineBorder; import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.DefaultDrawingSupplier;
import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotOrientation;
@ -116,11 +116,13 @@ public class SimulationPlot {
/*urls*/false /*urls*/false
); );
chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 23));
chart.setBackgroundPaint(new Color(240, 240, 240));
this.legendItems = new LegendItems(); this.legendItems = new LegendItems();
LegendTitle legend = new LegendTitle(legendItems); LegendTitle legend = new LegendTitle(legendItems);
legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legend.setFrame(new LineBorder()); legend.setFrame(BlockBorder.NONE);
legend.setBackgroundPaint(Color.white); legend.setBackgroundPaint(new Color(240, 240, 240));
legend.setPosition(RectangleEdge.BOTTOM); legend.setPosition(RectangleEdge.BOTTOM);
chart.addSubtitle(legend); chart.addSubtitle(legend);
@ -222,6 +224,15 @@ public class SimulationPlot {
plot.setDomainPannable(true); plot.setDomainPannable(true);
plot.setRangePannable(true); plot.setRangePannable(true);
// Plot appearance
plot.setBackgroundPaint(Color.white);
plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.lightGray);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.lightGray);
int axisno = 0; int axisno = 0;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
// Check whether axis has any data // Check whether axis has any data
@ -233,6 +244,7 @@ public class SimulationPlot {
axis.setLabel(axisLabel[i]); axis.setLabel(axisLabel[i]);
// axis.setRange(axes.get(i).getMinValue(), axes.get(i).getMaxValue()); // axis.setRange(axes.get(i).getMinValue(), axes.get(i).getMaxValue());
plot.setRangeAxis(axisno, axis); plot.setRangeAxis(axisno, axis);
axis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
double domainMin = data[i].getDomainLowerBound(true); double domainMin = data[i].getDomainLowerBound(true);
double domainMax = data[i].getDomainUpperBound(true); double domainMax = data[i].getDomainUpperBound(true);
@ -240,12 +252,22 @@ public class SimulationPlot {
plot.setDomainAxis(new PresetNumberAxis(domainMin, domainMax)); plot.setDomainAxis(new PresetNumberAxis(domainMin, domainMax));
// Add data and map to the axis // Add data and map to the axis
Color[] colors = {new Color(0,114,189), // Colors for data lines
new Color(217,83,25),
new Color(237,177,32),
new Color(126,49,142),
new Color(119,172,48),
new Color(77,190,238),
new Color(162,20,47)};
plot.setDataset(axisno, data[i]); plot.setDataset(axisno, data[i]);
ModifiedXYItemRenderer r = new ModifiedXYItemRenderer(branchCount); ModifiedXYItemRenderer r = new ModifiedXYItemRenderer(branchCount);
renderers.add(r); renderers.add(r);
plot.setRenderer(axisno, r); plot.setRenderer(axisno, r);
r.setBaseShapesVisible(initialShowPoints); r.setBaseShapesVisible(initialShowPoints);
r.setBaseShapesFilled(true); r.setBaseShapesFilled(true);
r.setSeriesPaint(0, colors[i]);
r.setSeriesPaint(1, colors[i+2]);
r.setSeriesPaint(2, colors[i+4]);
for (int j = 0; j < data[i].getSeriesCount(); j++) { for (int j = 0; j < data[i].getSeriesCount(); j++) {
Stroke lineStroke = new BasicStroke(PLOT_STROKE_WIDTH); Stroke lineStroke = new BasicStroke(PLOT_STROKE_WIDTH);
r.setSeriesStroke(j, lineStroke); r.setSeriesStroke(j, lineStroke);
@ -271,7 +293,7 @@ public class SimulationPlot {
plot.addDomainMarker(new ValueMarker(0)); plot.addDomainMarker(new ValueMarker(0));
plot.addRangeMarker(new ValueMarker(0)); plot.addRangeMarker(new ValueMarker(0));
plot.getDomainAxis().setLabelFont(new Font("Dialog", Font.BOLD, 14));
// Create list of events to show (combine event too close to each other) // Create list of events to show (combine event too close to each other)
this.eventList = buildEventInfo(); this.eventList = buildEventInfo();
@ -368,6 +390,7 @@ public class SimulationPlot {
m.setPaint(color); m.setPaint(color);
m.setLabelPaint(color); m.setLabelPaint(color);
m.setAlpha(0.7f); m.setAlpha(0.7f);
m.setLabelFont(new Font("Dialog", Font.PLAIN, 13));
plot.addDomainMarker(m); plot.addDomainMarker(m);
} }
@ -653,3 +676,4 @@ public class SimulationPlot {
} }
} }