Example usage for org.jfree.chart.plot XYPlot setDomainGridlinePaint

List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinePaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDomainGridlinePaint.

Prototype

public void setDomainGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the domain axis, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.ramadda.data.services.PointFormHandler.java

/**
 * make the jfreechart for the waveform//from ww  w .j  a va 2 s .c o m
 *
 * @param request the request
 * @param waveform the waveform
 * @param dataset the dataset
 *
 * @return chart
 */
private static JFreeChart createWaveformChart(Request request, Waveform waveform, XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "", // x axis label
            "", // y axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            false, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //        chart.getLegend().setVisible(false);

    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(false);
    float[] range = waveform.getRange();
    rangeAxis.setRange(new org.jfree.data.Range(range[0], range[1]));

    if (request.defined(ARG_WAVEFORM_AXIS_HIGH)) {
        domainAxis.setRange(new org.jfree.data.Range(request.get(ARG_WAVEFORM_AXIS_LOW, 0.0),
                request.get(ARG_WAVEFORM_AXIS_HIGH, 1000.0)));
    }

    domainAxis.setAutoRange(true);
    domainAxis.setAutoRangeIncludesZero(false);

    //        domainAxis.setVisible(false);
    //        rangeAxis.setFixedDimension(20);
    //        plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    //        plot.setAxisOffset(new RectangleInsets(5, 0, 5, 0));
    return chart;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private void onColorSchemeChanged() {
    defaultColorSchemeSupport = new SwingColorSchemeSupport() {
        @Override/*  www .  j  a v a  2  s  .  c om*/
        public ColorScheme getColorScheme() {
            return demetraUI.getColorScheme();
        }
    };

    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(defaultColorSchemeSupport.getPlotColor());
    plot.setDomainGridlinePaint(defaultColorSchemeSupport.getGridColor());
    plot.setRangeGridlinePaint(defaultColorSchemeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(defaultColorSchemeSupport.getBackColor());

    arimaRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.RED));
    dfmRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.BLUE));
    stdevRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.YELLOW));
}

From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java

/**
 * Creates a chart.// w  ww. j  a  v a  2 s  .  com
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Y", // x axis label
            "X", // y axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.rapidminer.gui.plotter.charts.MultipleScatterPlotter.java

@Override
public void updatePlotter() {

    prepareData();/*  w w  w . j  a  v a  2s . co m*/

    JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (xAxis >= 0) {
        int size = dataSet.getSeriesCount();
        chart = ChartFactory.createScatterPlot(null, // chart title
                null, // domain axis label
                null, // range axis label
                dataSet, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // URLs
        );

        // renderer settings
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        renderer.setBaseOutlinePaint(Color.BLACK);
        renderer.setUseOutlinePaint(true);
        renderer.setDrawOutlines(true);

        for (int i = 0; i < size; i++) {
            renderer.setSeriesShapesVisible(i, this.showPoints[plotIndexToColumnIndexMap.get(i)]);
            renderer.setSeriesLinesVisible(i, this.showLines[plotIndexToColumnIndexMap.get(i)]);
        }

        renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
    }

    // GENERAL CHART SETTINGS

    int size = dataSet.getSeriesCount();
    if (size <= 1) {
        chart.getXYPlot().getRenderer().setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else {
        for (int i = 0; i < dataSet.getSeriesCount(); i++) {
            chart.getXYPlot().getRenderer().setSeriesStroke(i,
                    new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            chart.getXYPlot().getRenderer().setSeriesPaint(i,
                    getColorProvider().getPointColor(i / (double) (dataSet.getSeriesCount() - 1)));
        }
    }

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(false);

    // general plot settings
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (xAxis >= 0) {
        if (dataTable.isNominal(xAxis)) {
            String[] values = new String[dataTable.getNumberOfValues(xAxis)];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(xAxis, i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(xAxis), values));
        } else if ((dataTable.isDate(xAxis)) || (dataTable.isDateTime(xAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(xAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (xLogScale) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(xAxis));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(xAxis));
                domainAxis.setAutoRangeStickyZero(false);
                domainAxis.setAutoRangeIncludesZero(false);
                plot.setDomainAxis(domainAxis);
            }
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

    // rotate labels
    if (isLabelRotating()) {
        plot.getDomainAxis().setTickLabelsVisible(true);
        plot.getDomainAxis().setVerticalTickLabels(true);
    }

    // range axis
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    // Chart Panel Settings
    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);

        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);

        // react to mouse clicks
        // ATTENTION: ACTIVATING THIS WILL LEAD TO SEVERE MEMORY LEAKS!!! (see below)
        panel.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                if (e.getTrigger().getClickCount() > 1) {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    if (entity != null) {
                        String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem()));
                        if (id != null) {
                            ObjectVisualizer visualizer = ObjectVisualizerService
                                    .getVisualizerForObject(dataTable);
                            visualizer.startVisualization(id);
                        }
                    }
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent e) {
            }
        });
    }

    // tooltips
    class CustomXYToolTipGenerator implements XYToolTipGenerator {

        public CustomXYToolTipGenerator() {
        }

        @Override
        public String generateToolTip(XYDataset dataset, int row, int column) {
            String id = idMap.get(new SeriesAndItem(row, column));
            if (id != null) {
                return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            } else {
                return "<html>(" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            }
        }
    }

    for (int i = 0; i < dataSet.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator());
    }
}

From source file:com.vgi.mafscaling.Rescale.java

private void createGraghPanel(JPanel dataPanel) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);/*w ww .ja v  a2s.com*/
    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);
}

From source file:GUI.ServerUI_Client.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Bandwidth Estimator", "Time/s", "Bandwidth",
            dataset, true, true, false);

    final XYPlot plot = result.getXYPlot();
    Color plotColor = new Color(245, 245, 245);
    plot.setBackgroundPaint(plotColor);//from w  w w.  j  av  a2s.co  m
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);
    ValueAxis xaxis = plot.getDomainAxis();
    //xaxis.setAutoRange(true);
    xaxis.setFixedAutoRange(5000.0);
    //xaxis.setVerticalTickLabels(true);
    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setAutoRange(true);
    //yaxis.setRange(0.0, 300.0);
    return result;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java

/**
 * Initializes the graph.  This method generates the backing {@link JFreeChart} from the time series and graph
 * parameter data./*from ww w.ja  va 2s . c om*/
 *
 * @throws GraphException if the initialization fails
 */
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL);
    String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL);
    Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE);
    Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, DEFAULT_GRAPH_STROKE);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET);

    checkSeriesType(data);
    @SuppressWarnings("unchecked")
    List<? extends TimeSeriesInterface> timeData = (List<? extends TimeSeriesInterface>) data;

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    int seriesCount = 1;
    for (TimeSeriesInterface series : timeData) {
        dataset.addSeries(buildTimeSeries(series, seriesCount));
        seriesCount += 1;
    }

    // actually create the chart
    this.chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, false, graphToolTip, false);

    // start customizing it
    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class,
            backgroundColor);
    Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class,
            backgroundColor);

    this.chart.setBackgroundPaint(backgroundColor);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset));
    plot.setDomainGridlinePaint(graphDomainGridlinePaint);
    plot.setRangeGridlinePaint(graphRangeGridlinePaint);

    if (graphBorder) {

    } else {
        plot.setOutlinePaint(null);
    }

    //Use a TextTitle to change the font of the graph title
    TextTitle title1 = new TextTitle();
    title1.setText(title);
    title1.setFont(titleFont);
    chart.setTitle(title1);

    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }
        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
    }

    boolean include0 = getParam(GraphSource.GRAPH_RANGE_INCLUDE_0, Boolean.class, true);
    NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
    double rangeLower = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, numAxis.getLowerBound());
    double rangeUpper = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, numAxis.getUpperBound());
    boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false);
    boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class,
            true);

    if (include0) {
        rangeLower = 0;
    }

    numAxis.setRange(rangeLower, rangeUpper);

    if (graphRangeIntegerTick) {
        numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    numAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible);
    setupFont(numAxis, GraphSource.GRAPH_Y_AXIS_FONT);

    if (params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT) instanceof Font) {
        numAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT)));
    }

    TimeResolution minimumResolution = getMinimumResolution(timeData);
    DateFormat dateFormat = getParam(GraphSource.GRAPH_DATE_FORMATTER, DateFormat.class,
            new DefaultDateFormatFactory().getFormat(minimumResolution));

    if (params.get(DATE_AXIS) instanceof DateAxis) {
        DateAxis dateAxis = (DateAxis) params.get(DATE_AXIS);
        dateAxis.setLabel(xLabel);
        plot.setDomainAxis(dateAxis);
    }
    DateAxis dateAxis = ((DateAxis) plot.getDomainAxis());
    dateAxis.setDateFormatOverride(dateFormat);

    if (params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT) instanceof Font) {
        dateAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT)));
    }

    int minTick = getParam(GraphSource.GRAPH_MIN_DOMAIN_TICK, Integer.class, 1);
    if (minTick <= 0) {
        minTick = 1;
    }

    dateAxis.setTickUnit(getDateTickUnit(minimumResolution, minTick), false, false);
    //dateAxis.setMinorTickMarksVisible(true);
    //dateAxis.setMinorTickCount(7);
    dateAxis.setMinorTickMarkOutsideLength(2);

    Integer minorTick = getParam(GraphSource.GRAPH_MINOR_TICKS, Integer.class, null);
    if (minorTick != null) {
        int minorVal = minorTick;
        if (minorVal > 0) {
            dateAxis.setMinorTickCount(minorVal);
        }
    }

    setupFont(dateAxis, GraphSource.GRAPH_X_AXIS_FONT);

    //double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    dateAxis.setLowerMargin(lowerMargin);

    //double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    dateAxis.setUpperMargin(upperMargin);

    Date domainLower = getParam(GraphSource.GRAPH_DOMAIN_LOWER_BOUND, Date.class, dateAxis.getMinimumDate());
    Date domainUpper = getParam(GraphSource.GRAPH_DOMAIN_UPPER_BOUND, Date.class, dateAxis.getMaximumDate());

    dateAxis.setRange(domainLower, domainUpper);

    // depending on the domain axis range, display either 1 tick per day, week, month or year
    TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7));
    standardUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1));
    dateAxis.setStandardTickUnits(standardUnits);

    TimeSeriesRenderer renderer = new TimeSeriesRenderer(dataset);
    setupRenderer(renderer, graphColor, graphShape, graphStroke);
    renderer.setBaseFillPaint(Color.BLACK);
    renderer.setSeriesOutlinePaint(0, Color.WHITE);

    //renderer.setUseOutlinePaint(true);

    plot.setRenderer(renderer);
    this.initialized = true;
}

From source file:net.sf.mzmine.chartbasics.chartthemes.ChartThemeParameters.java

public void applyToChart(JFreeChart chart) {
    // apply chart settings
    boolean showTitle = this.getParameter(ChartThemeParameters.showTitle).getValue();
    boolean changeTitle = this.getParameter(ChartThemeParameters.changeTitle).getValue();
    String title = this.getParameter(ChartThemeParameters.changeTitle).getEmbeddedParameter().getValue();
    boolean showLegends = this.getParameter(ChartThemeParameters.showLegends).getValue();

    boolean usexlabel = this.getParameter(ChartThemeParameters.xlabel).getValue();
    boolean useylabel = this.getParameter(ChartThemeParameters.ylabel).getValue();
    String xlabel = this.getParameter(ChartThemeParameters.xlabel).getEmbeddedParameter().getValue();
    String ylabel = this.getParameter(ChartThemeParameters.ylabel).getEmbeddedParameter().getValue();

    Color gbColor = this.getParameter(ChartThemeParameters.color).getValue();
    chart.setBackgroundPaint(gbColor);/*from  w w  w . j  a v  a2 s .  c o  m*/
    chart.getPlot().setBackgroundPaint(gbColor);

    if (changeTitle)
        chart.setTitle(title);
    chart.getTitle().setVisible(showTitle);
    ((List<Title>) chart.getSubtitles()).stream().forEach(t -> t.setVisible(showLegends));

    if (chart.getXYPlot() != null) {
        XYPlot p = chart.getXYPlot();
        if (usexlabel)
            p.getDomainAxis().setLabel(xlabel);
        if (useylabel)
            p.getRangeAxis().setLabel(ylabel);

        boolean xgrid = this.getParameter(ChartThemeParameters.xGridPaint).getValue();
        boolean ygrid = this.getParameter(ChartThemeParameters.yGridPaint).getValue();
        Color cxgrid = this.getParameter(ChartThemeParameters.xGridPaint).getEmbeddedParameter().getValue();
        Color cygrid = this.getParameter(ChartThemeParameters.yGridPaint).getEmbeddedParameter().getValue();
        p.setDomainGridlinesVisible(xgrid);
        p.setDomainGridlinePaint(cxgrid);
        p.setRangeGridlinesVisible(ygrid);
        p.setRangeGridlinePaint(cygrid);

        p.getDomainAxis().setVisible(this.getParameter(ChartThemeParameters.showXAxis).getValue());
        p.getRangeAxis().setVisible(this.getParameter(ChartThemeParameters.showYAxis).getValue());
    }
}

From source file:ec.ui.view.RevisionSaSeriesView.java

@Override
protected void onColorSchemeChange() {
    sRenderer.setBasePaint(themeSupport.getLineColor(ColorScheme.KnownColor.RED));
    revRenderer.setBasePaint(themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));

    XYPlot mainPlot = mainChart.getXYPlot();
    for (int i = 0; i < mainPlot.getSeriesCount(); i++) {
        revRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
        revRenderer.setSeriesShapesFilled(i, false);
        revRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));
    }//from w  w w .j  ava2  s .c om

    mainPlot.setBackgroundPaint(themeSupport.getPlotColor());
    mainPlot.setDomainGridlinePaint(themeSupport.getGridColor());
    mainPlot.setRangeGridlinePaint(themeSupport.getGridColor());
    mainChart.setBackgroundPaint(themeSupport.getBackColor());
}

From source file:org.n52.server.io.render.DiagramRenderer.java

/**
 * <pre>//from w  w  w  .j a va  2 s . c  o m
 * dataset :=  associated to one range-axis;
 * corresponds to one observedProperty;
 * may contain multiple series;
 * series :=   corresponds to a time series for one foi
 * </pre>
 *
 * .
 *
 * @param entireCollMap
 *            the entire coll map
 * @param options
 *            the options
 * @param begin
 *            the begin
 * @param end
 *            the end
 * @param compress
 * @return the j free chart
 */
public JFreeChart renderChart(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        Calendar begin, Calendar end, boolean compress) {

    DesignDescriptionList designDescriptions = buildUpDesignDescriptionList(options);

    /*** FIRST RUN ***/
    JFreeChart chart = initializeTimeSeriesChart();
    chart.setBackgroundPaint(Color.white);

    if (!this.isOverview) {
        chart.addSubtitle(new TextTitle(ConfigurationContext.COPYRIGHT, new Font(LABEL_FONT, Font.PLAIN, 9),
                Color.black, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM,
                new RectangleInsets(0, 0, 20, 20)));
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.setDomainGridlinesVisible(options.getGrid());
    plot.setRangeGridlinesVisible(options.getGrid());

    // add additional datasets:
    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setRange(begin.getTime(), end.getTime());
    dateAxis.setDateFormatOverride(new SimpleDateFormat());
    dateAxis.setTimeZone(end.getTimeZone());

    // add all axes
    String[] phenomenaIds = options.getAllPhenomenIds();
    // all the axis indices to map them later
    HashMap<String, Integer> axes = new HashMap<String, Integer>();
    for (int i = 0; i < phenomenaIds.length; i++) {
        axes.put(phenomenaIds[i], i);
        plot.setRangeAxis(i, new NumberAxis(phenomenaIds[i]));
    }

    // list range markers
    ArrayList<ValueMarker> referenceMarkers = new ArrayList<ValueMarker>();
    HashMap<String, double[]> referenceBounds = new HashMap<String, double[]>();

    // create all TS collections
    for (int i = 0; i < options.getProperties().size(); i++) {

        TimeseriesProperties prop = options.getProperties().get(i);

        String phenomenonId = prop.getPhenomenon();

        TimeSeriesCollection dataset = createDataset(entireCollMap, prop, phenomenonId, compress);
        dataset.setGroup(new DatasetGroup(prop.getTimeseriesId()));
        XYDataset additionalDataset = dataset;

        NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenomenonId));

        if (this.isOverview) {
            axe.setAutoRange(true);
            axe.setAutoRangeIncludesZero(false);
        } else if (prop.getAxisUpperBound() == prop.getAxisLowerBound() || prop.isAutoScale()) {
            if (prop.isZeroScaled()) {
                axe.setAutoRangeIncludesZero(true);
            } else {
                axe.setAutoRangeIncludesZero(false);
            }
        } else {
            if (prop.isZeroScaled()) {
                if (axe.getUpperBound() < prop.getAxisUpperBound()) {
                    axe.setUpperBound(prop.getAxisUpperBound());
                }
                if (axe.getLowerBound() > prop.getAxisLowerBound()) {
                    axe.setLowerBound(prop.getAxisLowerBound());
                }
            } else {
                axe.setRange(prop.getAxisLowerBound(), prop.getAxisUpperBound());
                axe.setAutoRangeIncludesZero(false);
            }
        }

        plot.setDataset(i, additionalDataset);
        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));

        // set bounds new for reference values
        if (!referenceBounds.containsKey(phenomenonId)) {
            double[] bounds = new double[] { axe.getLowerBound(), axe.getUpperBound() };
            referenceBounds.put(phenomenonId, bounds);
        } else {
            double[] bounds = referenceBounds.get(phenomenonId);
            if (bounds[0] >= axe.getLowerBound()) {
                bounds[0] = axe.getLowerBound();
            }
            if (bounds[1] <= axe.getUpperBound()) {
                bounds[1] = axe.getUpperBound();
            }
        }

        double[] bounds = referenceBounds.get(phenomenonId);
        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                Double value = prop.getRefValue(string).getValue();
                if (value <= bounds[0]) {
                    bounds[0] = value;
                } else if (value >= bounds[1]) {
                    bounds[1] = value;
                }
            }
        }

        Axis axis = prop.getAxis();
        if (axis == null) {
            axis = new Axis(axe.getUpperBound(), axe.getLowerBound());
        } else if (prop.isAutoScale()) {
            axis.setLowerBound(axe.getLowerBound());
            axis.setUpperBound(axe.getUpperBound());
            axis.setMaxY(axis.getMaxY());
            axis.setMinY(axis.getMinY());
        }
        prop.setAxisData(axis);
        this.axisMapping.put(prop.getTimeseriesId(), axis);

        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                referenceMarkers.add(new ValueMarker(prop.getRefValue(string).getValue(),
                        Color.decode(prop.getRefValue(string).getColor()),
                        new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)));
            }
        }

        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));
    }

    for (ValueMarker valueMarker : referenceMarkers) {
        plot.addRangeMarker(valueMarker);
    }

    // show actual time
    ValueMarker nowMarker = new ValueMarker(System.currentTimeMillis(), Color.orange,
            new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f));
    plot.addDomainMarker(nowMarker);

    if (!this.isOverview) {
        Iterator<Entry<String, double[]>> iterator = referenceBounds.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, double[]> boundsEntry = iterator.next();
            String phenId = boundsEntry.getKey();
            NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenId));
            axe.setAutoRange(true);
            // add a margin
            double marginOffset = (boundsEntry.getValue()[1] - boundsEntry.getValue()[0]) / 25;
            boundsEntry.getValue()[0] -= marginOffset;
            boundsEntry.getValue()[1] += marginOffset;
            axe.setRange(boundsEntry.getValue()[0], boundsEntry.getValue()[1]);
        }
    }

    /**** SECOND RUN ***/

    // set domain axis labels:
    plot.getDomainAxis().setLabelFont(label);
    plot.getDomainAxis().setLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setTickLabelFont(tickLabelDomain);
    plot.getDomainAxis().setTickLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setLabel(designDescriptions.getDomainAxisLabel());

    // define the design for each series:
    for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {
        TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(datasetIndex);

        for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) {

            String timeseriesId = (String) dataset.getSeries(seriesIndex).getKey();
            RenderingDesign dd = designDescriptions.get(timeseriesId);

            if (dd != null) {

                // LINESTYLE:
                String lineStyle = dd.getLineStyle();
                int width = dd.getLineWidth();
                if (this.isOverview) {
                    width = width / 2;
                    width = (width == 0) ? 1 : width;
                }
                // "1" is lineStyle "line"
                if (lineStyle.equalsIgnoreCase(LINE)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, false);
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                }
                // "2" is lineStyle "area"
                else if (lineStyle.equalsIgnoreCase(AREA)) {
                    plot.setRenderer(datasetIndex, new XYAreaRenderer());
                }
                // "3" is lineStyle "dotted"
                else if (lineStyle.equalsIgnoreCase(DOTTED)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(false, true);
                    ren.setShape(new Ellipse2D.Double(-width, -width, 2 * width, 2 * width));
                    plot.setRenderer(datasetIndex, ren);

                }
                // "4" is dashed
                else if (lineStyle.equalsIgnoreCase("4")) { // dashed
                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
                    renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND,
                            BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f * width, 4.0f * width }, 0.0f));
                    plot.setRenderer(datasetIndex, renderer);
                } else if (lineStyle.equalsIgnoreCase("5")) {
                    // lines and dots
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, true);
                    int thickness = 2 * width;
                    ren.setShape(new Ellipse2D.Double(-width, -width, thickness, thickness));
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                } else {
                    // default is lineStyle "line"
                    plot.setRenderer(datasetIndex, new XYLineAndShapeRenderer(true, false));
                }

                plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, dd.getColor());

                // plot.getRenderer(datasetIndex).setShapesVisible(true);

                XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
                XYURLGenerator urlGenerator = new MetadataInURLGenerator(designDescriptions);

                plot.getRenderer(datasetIndex).setBaseToolTipGenerator(toolTipGenerator);
                plot.getRenderer(datasetIndex).setURLGenerator(urlGenerator);

                // GRID:
                // PROBLEM: JFreeChart only allows to switch the grid on/off
                // for the whole XYPlot. And the
                // grid will always be displayed for the first series in the
                // plot. I'll always show the
                // grid.
                // --> plot.setDomainGridlinesVisible(visible)

                // RANGE AXIS LABELS:
                if (isOverview) {
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelsVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setTickMarksVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setVisible(false);
                } else {
                    plot.getRangeAxisForDataset(datasetIndex).setLabelFont(label);
                    plot.getRangeAxisForDataset(datasetIndex).setLabelPaint(LABEL_COLOR);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelFont(tickLabelDomain);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelPaint(LABEL_COLOR);
                    StringBuilder unitOfMeasure = new StringBuilder();
                    unitOfMeasure.append(dd.getPhenomenon().getLabel());
                    String uomLabel = dd.getUomLabel();
                    if (uomLabel != null && !uomLabel.isEmpty()) {
                        unitOfMeasure.append(" (").append(uomLabel).append(")");
                    }
                    plot.getRangeAxisForDataset(datasetIndex).setLabel(unitOfMeasure.toString());
                }
            }
        }
    }
    return chart;
}