Search in sources :

Example 1 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator in project mafscaling by vimsh.

the class VVTCalc method createChart.

protected void createChart(int index, JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    chart.setBorderVisible(true);
    ChartPanel chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanels[index] = chartPanel;
    chartPanel.setFocusable(true);
    chartPanel.setAutoscrolls(true);
    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = index;
    plotPanel.add(chartPanel, gbl_chartPanel);
    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
    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();
        }
    });
    XYLineAndShapeRenderer lineRendererBest = new XYLineAndShapeRenderer();
    lineRendererBest.setUseFillPaint(true);
    lineRendererBest.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
    lineRendererBest.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {

        private static final long serialVersionUID = -5917538704894141801L;

        public String generateLabel(XYDataset dataset, int series) {
            XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
            return xys.getDescription();
        }
    });
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRendererBest.setSeriesPaint(0, Color.DARK_GRAY);
    lineRendererBest.setSeriesStroke(0, stroke);
    lineRendererBest.setSeriesPaint(1, Color.BLACK);
    lineRendererBest.setSeriesStroke(1, stroke);
    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);
    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, new XYSeriesCollection());
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    XYSeriesCollection bestVVTDataset = new XYSeriesCollection();
    plot.setDataset(1, bestVVTDataset);
    plot.setRenderer(1, lineRendererBest);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    LegendTitle legend = new LegendTitle(plot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) BasicStroke(java.awt.BasicStroke) GridBagConstraints(java.awt.GridBagConstraints) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) ChartPanel(org.jfree.chart.ChartPanel) Insets(java.awt.Insets) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) 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) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 2 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator in project mafscaling by vimsh.

the class ACompCalc method createChart.

protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    chart.setBorderVisible(true);
    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseZoomable(false);
    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 1;
    plotPanel.add(chartPanel, gbl_chartPanel);
    XYDotRenderer dotRenderer = new XYDotRenderer();
    dotRenderer.setSeriesPaint(0, new Color(0, 51, 102));
    dotRenderer.setDotHeight(3);
    dotRenderer.setDotWidth(3);
    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    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.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
    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();
        }
    });
    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);
    XYSeriesCollection scatterDataset = new XYSeriesCollection(runData);
    XYSeriesCollection lineDataset = new XYSeriesCollection();
    trendData.setDescription(trendDataName);
    lineDataset.addSeries(trendData);
    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, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.setDataset(1, scatterDataset);
    plot.setRenderer(1, dotRenderer);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 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) XYSeries(org.jfree.data.xy.XYSeries) GridBagConstraints(java.awt.GridBagConstraints) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) ChartPanel(org.jfree.chart.ChartPanel) Insets(java.awt.Insets) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) 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) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 3 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator in project pentaho-platform by pentaho.

the class JFreeChartEngine method createXYSeriesCollectionChart.

private static JFreeChart createXYSeriesCollectionChart(final XYSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel) : new NumberAxis(domainAxisLabel);
    domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
    domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());
    ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    AbstractXYItemRenderer renderer = null;
    switch(chartDefinition.getChartType()) {
        case LINE_CHART_TYPE:
            renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
            ((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
            ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
            break;
        case AREA_CHART_TYPE:
            renderer = new XYAreaRenderer();
            break;
        case STEP_CHART_TYPE:
            renderer = new XYStepRenderer();
            break;
        case STEP_AREA_CHART_TYPE:
            renderer = new XYStepAreaRenderer();
            break;
        case DIFFERENCE_CHART_TYPE:
            renderer = new XYDifferenceRenderer();
            break;
        case DOT_CHART_TYPE:
            renderer = new XYDotRenderer();
            ((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
            ((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
            break;
        default:
            // should log an error if invalid chart type passed in - at least return null for no renderer
            return null;
    }
    if (renderer != null && legend) {
        renderer.setLegendItemURLGenerator(new StandardXYSeriesLabelGenerator());
    }
    if (tooltips) {
        XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new DecimalFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
        renderer.setToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) DecimalFormat(java.text.DecimalFormat) NumberAxis3D(org.jfree.chart.axis.NumberAxis3D) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) XYDotRenderer(org.jfree.chart.renderer.xy.XYDotRenderer) XYDifferenceRenderer(org.jfree.chart.renderer.xy.XYDifferenceRenderer) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYLine3DRenderer(org.jfree.chart.renderer.xy.XYLine3DRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYStepRenderer(org.jfree.chart.renderer.xy.XYStepRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator)

Example 4 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator in project spf4j by zolyfarkas.

the class Charts method createJFreeChart.

private static JFreeChart createJFreeChart(final String chartName, final String uom, final XYDataset timeseriescollection) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(chartName, "Time", uom, timeseriescollection, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setVerticalTickLabels(true);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setLegendItemToolTipGenerator(new StandardXYSeriesLabelGenerator("Tooltip {0}"));
    return jfreechart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator 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

StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)11 JFreeChart (org.jfree.chart.JFreeChart)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 XYPlot (org.jfree.chart.plot.XYPlot)7 DecimalFormat (java.text.DecimalFormat)6 NumberAxis (org.jfree.chart.axis.NumberAxis)6 BasicStroke (java.awt.BasicStroke)5 Color (java.awt.Color)5 Font (java.awt.Font)5 GridBagConstraints (java.awt.GridBagConstraints)5 Stroke (java.awt.Stroke)5 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)5 LegendTitle (org.jfree.chart.title.LegendTitle)5 XYDataset (org.jfree.data.xy.XYDataset)5 XYSeries (org.jfree.data.xy.XYSeries)5 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)5 Insets (java.awt.Insets)4 ChartPanel (org.jfree.chart.ChartPanel)4 Test (org.junit.Test)4 ValueAxis (org.jfree.chart.axis.ValueAxis)3