Search in sources :

Example 1 with XYSplineRenderer

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);
}
Also used : DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 2 with XYSplineRenderer

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);
}
Also used : DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 3 with XYSplineRenderer

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);
}
Also used : BasicStroke(java.awt.BasicStroke) GridBagConstraints(java.awt.GridBagConstraints) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) DecimalFormat(java.text.DecimalFormat) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 4 with XYSplineRenderer

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);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) XYPlot(org.jfree.chart.plot.XYPlot) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Map(java.util.Map) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with XYSplineRenderer

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);
}
Also used : BasicStroke(java.awt.BasicStroke) XYSeries(org.jfree.data.xy.XYSeries) GridBagConstraints(java.awt.GridBagConstraints) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) NumberAxis(org.jfree.chart.axis.NumberAxis) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) Color(java.awt.Color) DecimalFormat(java.text.DecimalFormat) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) XYDotRenderer(org.jfree.chart.renderer.xy.XYDotRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)6 XYSplineRenderer (org.jfree.chart.renderer.xy.XYSplineRenderer)6 XYPlot (org.jfree.chart.plot.XYPlot)4 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)4 BasicStroke (java.awt.BasicStroke)3 Color (java.awt.Color)3 Font (java.awt.Font)3 GridBagConstraints (java.awt.GridBagConstraints)3 Stroke (java.awt.Stroke)3 DecimalFormat (java.text.DecimalFormat)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 ValueAxis (org.jfree.chart.axis.ValueAxis)3 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)3 LegendTitle (org.jfree.chart.title.LegendTitle)3 XYSeries (org.jfree.data.xy.XYSeries)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)2 DefaultXYDataset (org.jfree.data.xy.DefaultXYDataset)2