Search in sources :

Example 51 with DateAxis

use of org.jfree.chart.axis.DateAxis in project asl-sensor-suite by usgs.

the class InputPanel method setPlotParameters.

private void setPlotParameters(XYPlot xyPlot, int index) {
    DateAxis dateAxis = new DateAxis();
    dateAxis.setLabel("UTC Time (Year.Day.Hour:Minute)");
    Font bold = dateAxis.getLabelFont();
    bold = bold.deriveFont(Font.BOLD);
    dateAxis.setLabelFont(bold);
    dateAxis.setDateFormatOverride(ExperimentPanel.DATE_TIME_FORMAT.get());
    xyPlot.setDomainAxis(dateAxis);
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabel("Counts");
    numberAxis.setAutoRange(true);
    numberAxis.setAutoRangeIncludesZero(false);
    numberAxis.setLabelFont(bold);
    xyPlot.setRangeAxis(numberAxis);
    int colorIndex = index % defaultColor.length;
    xyPlot.getRenderer().setSeriesPaint(0, defaultColor[colorIndex]);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Font(java.awt.Font)

Example 52 with DateAxis

use of org.jfree.chart.axis.DateAxis in project pentaho-platform by pentaho.

the class JFreeChartEngine method createTimeSeriesCollectionChart.

private static JFreeChart createTimeSeriesCollectionChart(final TimeSeriesCollectionChartDefinition 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();
    DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
    ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    XYItemRenderer 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 (tooltips) {
        XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(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 : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) 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) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with DateAxis

use of org.jfree.chart.axis.DateAxis in project pentaho-platform by pentaho.

the class JFreeChartEngine method updatePlot.

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());
    plot.setNoDataMessage(chartDefinition.getNoDataMessage());
    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }
    // TODO define outline stroke
    plot.setOutlineStroke(null);
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }
            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }
    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            // $NON-NLS-1$
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}");
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext(); ) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                // $NON-NLS-1$
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})");
                pie.setLabelGenerator(labelGen);
            } else {
                // $NON-NLS-1$
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }
        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));
    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }
        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }
        }
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) MeterInterval(org.jfree.chart.plot.MeterInterval) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Range(org.jfree.data.Range) CategoryPlot(org.jfree.chart.plot.CategoryPlot) MeterPlot(org.jfree.chart.plot.MeterPlot) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) XYPlot(org.jfree.chart.plot.XYPlot) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) Iterator(java.util.Iterator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) List(java.util.List) DefaultDrawingSupplier(org.jfree.chart.plot.DefaultDrawingSupplier)

Example 54 with DateAxis

use of org.jfree.chart.axis.DateAxis in project lotro-companion by dmorcellet.

the class CraftingHistoryChartController method buildChart.

private JFreeChart buildChart() {
    final Profession profession = _stats.getProfession();
    String title = "";
    if (_showTitle) {
        title = profession.getName();
    }
    updateData();
    JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Tier", _data, PlotOrientation.VERTICAL, true, true, false);
    Color foregroundColor = GuiFactory.getForegroundColor();
    Paint backgroundPaint = GuiFactory.getBackgroundPaint();
    jfreechart.setBackgroundPaint(backgroundPaint);
    TextTitle t = new TextTitle(title);
    t.setFont(t.getFont().deriveFont(24.0f));
    t.setPaint(foregroundColor);
    jfreechart.setTitle(t);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(false);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
    XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {

        @Override
        public String generateLabelString(XYDataset dataset, int series, int item) {
            String label;
            int tier = (int) dataset.getYValue(series, item);
            if (tier == 0) {
                label = "Started profession";
            } else {
                CraftingLevel level = profession.getByTier(tier);
                if (level != null) {
                    if (series == 0)
                        label = level.getMastery().getLabel();
                    else if (series == 1)
                        label = level.getProficiency().getLabel();
                    else
                        label = "???";
                } else {
                    label = "???";
                }
            }
            double timestamp = dataset.getXValue(series, item);
            String date = Formats.getDateString(Long.valueOf((long) timestamp));
            return label + " (" + date + ")";
        }
    };
    xysteparearenderer.setBaseToolTipGenerator(tooltip);
    xysteparearenderer.setSeriesPaint(0, new Color(255, 235, 31));
    xysteparearenderer.setSeriesPaint(1, new Color(130, 80, 57));
    xyplot.setRenderer(xysteparearenderer);
    DateAxis axis = (DateAxis) xyplot.getDomainAxis();
    DateFormat sdf = LocalizedFormats.getDateFormat();
    axis.setDateFormatOverride(sdf);
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
    valueAxis.setAutoRange(false);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    CraftingLevel maxLevel = profession.getMaximumLevel();
    valueAxis.setRange(0, maxLevel.getTier());
    NumberFormat nf = new NumberFormat() {

        private String format(int number) {
            CraftingLevel level = profession.getByTier(number);
            String ret = (level != null) ? level.getProficiency().getLabel() : "???";
            return ret;
        }

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    };
    valueAxis.setNumberFormatOverride(nf);
    LegendTitle legend = jfreechart.getLegend();
    legend.setItemPaint(foregroundColor);
    legend.setBackgroundPaint(backgroundPaint);
    return jfreechart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) FieldPosition(java.text.FieldPosition) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint) TextTitle(org.jfree.chart.title.TextTitle) Profession(delta.games.lotro.lore.crafting.Profession) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) DateFormat(java.text.DateFormat) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) CraftingLevel(delta.games.lotro.lore.crafting.CraftingLevel) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Example 55 with DateAxis

use of org.jfree.chart.axis.DateAxis in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createBoxAndWhiskerChart.

/**
 * Creates and returns a default instance of a box and whisker chart.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param timeAxisLabel  a label for the time axis ({@code null}
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis ({@code null}
 *                        permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel, BoxAndWhiskerXYDataset dataset, boolean legend) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) XYBoxAndWhiskerRenderer(org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis)

Aggregations

DateAxis (org.jfree.chart.axis.DateAxis)108 XYPlot (org.jfree.chart.plot.XYPlot)82 NumberAxis (org.jfree.chart.axis.NumberAxis)63 JFreeChart (org.jfree.chart.JFreeChart)52 SimpleDateFormat (java.text.SimpleDateFormat)34 ValueAxis (org.jfree.chart.axis.ValueAxis)33 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)32 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)24 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)23 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)22 Color (java.awt.Color)17 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)17 StandardXYURLGenerator (org.jfree.chart.urls.StandardXYURLGenerator)15 Date (java.util.Date)14 DateFormat (java.text.DateFormat)13 XYBarRenderer (org.jfree.chart.renderer.xy.XYBarRenderer)12 XYDataset (org.jfree.data.xy.XYDataset)11 Paint (java.awt.Paint)10 LegendTitle (org.jfree.chart.title.LegendTitle)10 Map (java.util.Map)9