use of org.jfree.chart.renderer.xy.XYSplineRenderer in project dkpro-lab by dkpro.
the class ChartUtilTest method testPDF.
@Test
public void testPDF() throws Exception {
double[][] data = new double[2][10];
for (int n = 1; n < 10; n++) {
data[0][n] = 1.0 / n;
data[1][n] = 1.0 - (1.0 / n);
}
DefaultXYDataset dataset = new DefaultXYDataset();
dataset.addSeries("data", data);
JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset, PlotOrientation.VERTICAL, false, false, false);
chart.getXYPlot().setRenderer(new XYSplineRenderer());
chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0);
File tmp = File.createTempFile("testfile", ".pdf");
try (OutputStream os = new FileOutputStream(tmp)) {
ChartUtil.writeChartAsPDF(os, chart, 400, 400);
}
// Do not have an assert here because the creation date encoded in the PDF changes
// String ref = FileUtils.readFileToString(new File("src/test/resources/chart/test.pdf"),
// "UTF-8");
// String actual = FileUtils.readFileToString(tmp, "UTF-8");
// assertEquals(ref, actual);
}
use of org.jfree.chart.renderer.xy.XYSplineRenderer in project dkpro-lab by dkpro.
the class ChartUtilTest method testSvg.
@Test
public void testSvg() throws Exception {
double[][] data = new double[2][10];
for (int n = 1; n < 10; n++) {
data[0][n] = 1.0 / n;
data[1][n] = 1.0 - (1.0 / n);
}
DefaultXYDataset dataset = new DefaultXYDataset();
dataset.addSeries("data", data);
JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset, PlotOrientation.VERTICAL, false, false, false);
chart.getXYPlot().setRenderer(new XYSplineRenderer());
chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0);
File tmp = File.createTempFile("testfile", ".svg");
try (OutputStream os = new FileOutputStream(tmp)) {
ChartUtil.writeChartAsSVG(os, chart, 400, 400);
}
// String ref = FileUtils.readFileToString(new File("src/test/resources/chart/test.svg"),
// "UTF-8");
// String actual = FileUtils.readFileToString(tmp, "UTF-8");
// assertEquals(ref, actual);
}
use of org.jfree.chart.renderer.xy.XYSplineRenderer in project mafscaling by vimsh.
the class MafRescale method createGraghPanel.
private void createGraghPanel(JPanel dataPanel) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
mafChartPanel = new MafChartPanel(chart, this);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
gbl_chartPanel.insets = insets0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 2;
dataPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel);
XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesStroke(1, stroke);
lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5));
ValueAxis mafvDomain = new NumberAxis(XAxisName);
ValueAxis mafgsRange = new NumberAxis(YAxisName);
XYSeriesCollection lineDataset = new XYSeriesCollection();
lineDataset.addSeries(currMafData);
lineDataset.addSeries(corrMafData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, mafvDomain);
plot.setRangeAxis(0, mafgsRange);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.renderer.xy.XYSplineRenderer in project uncommons-maths by dwdyer.
the class GraphPanel method generateGraph.
public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues, double expectedMean, double expectedStandardDeviation, boolean discrete) {
XYSeriesCollection dataSet = new XYSeriesCollection();
XYSeries observedSeries = new XYSeries("Observed");
dataSet.addSeries(observedSeries);
XYSeries expectedSeries = new XYSeries("Expected");
dataSet.addSeries(expectedSeries);
for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
observedSeries.add(entry.getKey(), entry.getValue());
}
for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
expectedSeries.add(entry.getKey(), entry.getValue());
}
JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet, PlotOrientation.VERTICAL, true, false, false);
XYPlot plot = (XYPlot) chart.getPlot();
if (discrete) {
// Render markers at each data point (these discrete points are the
// distibution, not the lines between them).
plot.setRenderer(new XYLineAndShapeRenderer());
} else {
// Render smooth lines between points for a continuous distribution.
XYSplineRenderer renderer = new XYSplineRenderer();
renderer.setBaseShapesVisible(false);
plot.setRenderer(renderer);
}
chartPanel.setChart(chart);
}
use of org.jfree.chart.renderer.xy.XYSplineRenderer in project mafscaling by vimsh.
the class AMafScaling method createChart.
protected void createChart(JPanel plotPanel, String y2AxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
mafChartPanel = new MafChartPanel(chart, this);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.insets = insets3;
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel);
XYDotRenderer dotRenderer = new XYDotRenderer();
dotRenderer.setSeriesPaint(0, new Color(0, 51, 102));
dotRenderer.setDotHeight(3);
dotRenderer.setDotWidth(3);
XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesStroke(1, stroke);
lineRenderer.setSeriesStroke(2, stroke);
lineRenderer.setSeriesPaint(0, new Color(34, 139, 34));
lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
lineRenderer.setSeriesPaint(2, new Color(201, 0, 0));
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5));
lineRenderer.setSeriesShape(2, ShapeUtilities.createDownTriangle((float) 2.5));
mafChartPanel.enablePointsDrag(0);
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
ValueAxis mafvDomain = new NumberAxis(XAxisName);
ValueAxis mafgsRange = new NumberAxis(Y1AxisName);
ValueAxis afrerrRange = new NumberAxis(y2AxisName);
XYSeriesCollection scatterDataset = new XYSeriesCollection(runData);
XYSeriesCollection lineDataset = new XYSeriesCollection();
currMafData.setDescription(currentDataName);
corrMafData.setDescription(correctedDataName);
smoothMafData.setDescription(smoothedDataName);
lineDataset.addSeries(smoothMafData);
lineDataset.addSeries(corrMafData);
lineDataset.addSeries(currMafData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, mafvDomain);
plot.setRangeAxis(0, mafgsRange);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, scatterDataset);
plot.setRenderer(1, dotRenderer);
plot.setRangeAxis(1, afrerrRange);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
Aggregations