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

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

Introduction

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

Prototype

public void setRangeAxisLocation(int index, AxisLocation location) 

Source Link

Document

Sets the location for a range axis and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.XYTickLabelDemo.java

/**
 * Creates the demo chart.//from   w w  w .  ja  va 2 s . co m
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    // create some sample data

    final XYSeries series1 = new XYSeries("Something");
    series1.add(0.0, 30.0);
    series1.add(1.0, 10.0);
    series1.add(2.0, 40.0);
    series1.add(3.0, 30.0);
    series1.add(4.0, 50.0);
    series1.add(5.0, 50.0);
    series1.add(6.0, 70.0);
    series1.add(7.0, 70.0);
    series1.add(8.0, 80.0);

    final XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(series1);

    final XYSeries series2 = new XYSeries("Something else");
    series2.add(0.0, 5.0);
    series2.add(1.0, 4.0);
    series2.add(2.0, 1.0);
    series2.add(3.0, 5.0);
    series2.add(4.0, 0.0);

    final XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series2);

    // create the chart

    final JFreeChart result = ChartFactory.createXYLineChart("Tick Label Demo", "Domain Axis 1", "Range Axis 1",
            dataset1, PlotOrientation.VERTICAL, false, true, false);

    result.setBackgroundPaint(Color.white);
    final XYPlot plot = result.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // DOMAIN AXIS 2
    final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2");
    xAxis2.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(1, xAxis2);

    // RANGE AXIS 2
    final DateAxis yAxis1 = new DateAxis("Range Axis 1");
    plot.setRangeAxis(yAxis1);

    final DateAxis yAxis2 = new DateAxis("Range Axis 2");
    plot.setRangeAxis(1, yAxis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, dataset2);
    plot.mapDatasetToDomainAxis(1, 1);
    plot.mapDatasetToRangeAxis(1, 1);

    return result;
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getDailyIntegratedStats(Session s) throws CloneNotSupportedException {
    JFreeChart chart;/*from   w  ww  .  j  a v  a 2s. c  o  m*/
    List<DailyStatsModel> stats = (new SafeHibList<DailyStatsModel>(
            s.createQuery("select ds from DailyStatsModel as ds where day<? and day>=? order by day desc")
                    .setDate(0, new Date()).setDate(1, GraphServlet.getStartDate()))).list();
    TimeSeriesCollection theData = new TimeSeriesCollection();
    TimeSeriesCollection theData2 = new TimeSeriesCollection();

    TimeSeries users = new TimeSeries("Total Users", Day.class);
    theData.addSeries(users);

    TimeSeries regulars = new TimeSeries("Regular Members", Day.class);
    theData2.addSeries(regulars);

    int numUsers = Helpers.getGroup("Org").getNumMembers();
    int numReg = Helpers.getGroup("Regular").getNumMembers();

    for (DailyStatsModel ds : stats) {
        Day theDay = new Day(ds.getDay());
        users.add(theDay, numUsers);
        regulars.add(theDay, numReg);
        numUsers -= (ds.getMailinglistsignups() + ds.getSignups() - ds.getDeletions());
        numReg -= (ds.getRegupgrades() - ds.getRegdowngrades());
    }

    chart = ChartFactory.createTimeSeriesChart("Membership", "Day", "Users", theData, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis2 = new NumberAxis("Regular Members");
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, MovingAverage.createMovingAverage(theData2, "", 14, 0));
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer = (XYLineAndShapeRenderer) renderer.clone();
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    plot.setRenderer(1, renderer);
    return chart;
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getLastLogin(Session s) throws CloneNotSupportedException {

    Integer numCurrentLogins = ((Long) s
            .createQuery("select count(*) from UserModel "
                    + "where currentLogin is not null and currentLogin >= :date")
            .setDate("date", getStartDate()).uniqueResult()).intValue();

    List currentStats = s//from www . ja v a2  s .  c o  m
            .createSQLQuery("SELECT DATE(currentLogin) as date, count( * ) as lastLogins "
                    + "FROM users where currentLogin is not null  and currentLogin >= :date "
                    + "GROUP BY DATE( currentLogin )")
            .addScalar("date", Hibernate.DATE).addScalar("lastLogins", Hibernate.INTEGER)
            .setDate("date", getStartDate()).list();

    TimeSeriesCollection theData = new TimeSeriesCollection();
    TimeSeriesCollection theData2 = new TimeSeriesCollection();

    TimeSeries current = new TimeSeries("Num Latest Sign-ins", Day.class);
    theData.addSeries(current);
    TimeSeries current2 = new TimeSeries("Signed-in Users Since", Day.class);
    theData2.addSeries(current2);

    for (Object ds : currentStats) {
        Date date = (Date) ((Object[]) ds)[0];
        Day day = new Day(date);
        Integer integer = (Integer) ((Object[]) ds)[1];
        current.add(day, integer);
        numCurrentLogins -= integer.intValue();
        current2.add(day, numCurrentLogins);

    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Sign-in Recency", "Day", "Sign-ins", theData, true,
            true, true);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis2 = new NumberAxis("Users");
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, theData2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    renderer = (XYLineAndShapeRenderer) renderer.clone();
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f));
    plot.setRenderer(1, renderer);
    return chart;
}

From source file:com.android.ddmuilib.log.event.DisplayGraph.java

/**
* Returns a {@link TimeSeriesCollection} for a specific {@link com.android.ddmlib.log.EventValueDescription.ValueType}.
* If the data set is not yet created, it is first allocated and set up into the
* {@link org.jfree.chart.JFreeChart} object.
* @param type the {@link com.android.ddmlib.log.EventValueDescription.ValueType} of the data set.
* @param accumulateValues/*  w  w  w .  j  a  v  a 2  s.co m*/
*/
private TimeSeriesCollection getValueDataset(EventValueDescription.ValueType type, boolean accumulateValues) {
    TimeSeriesCollection dataset = mValueTypeDataSetMap.get(type);
    if (dataset == null) {
        // create the data set and store it in the map
        dataset = new TimeSeriesCollection();
        mValueTypeDataSetMap.put(type, dataset);

        // create the renderer and configure it depending on the ValueType
        AbstractXYItemRenderer renderer;
        if (type == EventValueDescription.ValueType.PERCENT && accumulateValues) {
            renderer = new XYAreaRenderer();
        } else {
            XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
            r.setBaseShapesVisible(type != EventValueDescription.ValueType.PERCENT);

            renderer = r;
        }

        // set both the dataset and the renderer in the plot object.
        XYPlot xyPlot = mChart.getXYPlot();
        xyPlot.setDataset(mDataSetCount, dataset);
        xyPlot.setRenderer(mDataSetCount, renderer);

        // put a new axis label, and configure it.
        NumberAxis axis = new NumberAxis(type.toString());

        if (type == EventValueDescription.ValueType.PERCENT) {
            // force percent range to be (0,100) fixed.
            axis.setAutoRange(false);
            axis.setRange(0., 100.);
        }

        // for the index, we ignore the occurrence dataset
        int count = mDataSetCount;
        if (mOccurrenceDataSet != null) {
            count--;
        }

        xyPlot.setRangeAxis(count, axis);
        if ((count % 2) == 0) {
            xyPlot.setRangeAxisLocation(count, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            xyPlot.setRangeAxisLocation(count, AxisLocation.TOP_OR_RIGHT);
        }

        // now we link the dataset and the axis
        xyPlot.mapDatasetToRangeAxis(mDataSetCount, count);

        mDataSetCount++;
    }

    return dataset;
}

From source file:org.jfree.chart.demo.MultipleAxisDemo3.java

/**
 * Creates the demo chart.//ww w  . j  a  va 2  s  .  com
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // DOMAIN AXIS 2
    final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2");
    xAxis2.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(1, xAxis2);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    // DOMAIN AXIS 3
    final NumberAxis xAxis3 = new NumberAxis("Domain Axis 3");
    xAxis2.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(2, xAxis3);
    plot.setDomainAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT);

    // RANGE AXIS 2
    final NumberAxis yAxis2 = new NumberAxis("Range Axis 2");
    plot.setRangeAxis(1, yAxis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToDomainAxis(1, 1);
    plot.mapDatasetToRangeAxis(1, 1);

    return chart;

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java

protected void configureLineChart(final XYPlot plot) {
    final XYDataset linesDataset = createLinesDataset();
    if (linesDataset == null || linesDataset.getSeriesCount() == 0) {
        return;/*from   w  w  w .jav  a2 s  .  c o  m*/
    }

    //Create Axis Objects
    final ValueAxis linesAxis;
    if (isSharedRangeAxis()) {
        linesAxis = plot.getRangeAxis();
    } else if (isThreeD()) {
        linesAxis = new NumberAxis3D(getSecondValueAxisLabel());
    } else {
        linesAxis = new NumberAxis(getSecondValueAxisLabel());
    }

    final XYItemRenderer lineRenderer;
    if (isThreeD()) {
        lineRenderer = new XYLine3DRenderer();
    } else {
        lineRenderer = new XYLineAndShapeRenderer();
    }

    plot.setRenderer(1, lineRenderer);
    plot.setDataset(1, linesDataset);
    plot.setRangeAxis(1, linesAxis);

    //map lines to second axis
    plot.mapDatasetToRangeAxis(1, 1);

    //set location of second axis
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
}

From source file:net.sf.jasperreports.engine.fill.JRFillChart.java

/**
 * Build and configure a multiple axis chart.  A multiple axis chart support more than
 * one range axis.  Multiple datasets using different ranges can be displayed as long as
 * they share a common domain axis.  Each dataset can be rendered differently, so one chart
 * can contain (for example) two line charts, a bar chart and an area chart.
 * <br><br>/*  w ww.  ja  v  a  2  s.  c o m*/
 * Multiple axis charts are handled differently than the other chart types.  They do not
 * have a dataset, as each chart that is added to the multiple axis chart has its own
 * dataset.  For simplicity, each dataset is treated as its own chart, and in fact we
 * reuse the design of all the chart types and let JFreeChart actually run them.  Then
 * we pull out the bits we need and add it to the common chart.  All the plot and chart
 * options on the nested charts is ignored, and all formatting is controlled by the plot
 * attached to the multiAxisChart.  The one exception is seriesColor, which can be used in
 * a nested report to specify a color for a specific series in that report.
 *
 * @param evaluation current expression evaluation phase
 * @throws JRException
 */
protected void createMultiAxisChart(byte evaluation) throws JRException {
    // A multi axis chart has to have at least one axis and chart specified.
    // Create the first axis as the base plot, and then go ahead and create the
    // charts for any additional axes.  Just take the renderer and data series
    // from those charts and add them to the first one.
    Plot mainPlot = null;

    JRFillMultiAxisPlot jrPlot = (JRFillMultiAxisPlot) getPlot();

    // create a multi axis hyperlink provider
    MultiAxisChartHyperlinkProvider multiHyperlinkProvider = new MultiAxisChartHyperlinkProvider();

    // Generate the main plot from the first axes specified.
    Iterator<JRChartAxis> iter = jrPlot.getAxes().iterator();
    if (iter.hasNext()) {
        JRFillChartAxis axis = (JRFillChartAxis) iter.next();
        JRFillChart fillChart = axis.getFillChart();

        //a JFreeChart object should be obtained first; the rendering type should be always "vector"

        jfreeChart = fillChart.evaluateChart(evaluation);
        //FIXME honor printWhenExpression
        // Override the plot from the first axis with the plot for the multi-axis
        // chart.
        //FIXME is the above comment true? 
        //configureChart(jfreeChart, getPlot(), evaluation);
        mainPlot = jfreeChart.getPlot();
        ChartHyperlinkProvider axisHyperlinkProvider = fillChart.getHyperlinkProvider();

        if (mainPlot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) mainPlot;
            categoryPlot.setRangeAxisLocation(0, getChartAxisLocation(axis));
            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(categoryPlot.getDataset(), axisHyperlinkProvider);
            }
        } else if (mainPlot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) mainPlot;
            xyPlot.setRangeAxisLocation(0, getChartAxisLocation(axis));
            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(xyPlot.getDataset(), axisHyperlinkProvider);
            }
        }
    }

    // Now handle all the extra axes, if any.
    int axisNumber = 0;
    while (iter.hasNext()) {
        JRFillChartAxis chartAxis = (JRFillChartAxis) iter.next();
        JRFillChart fillChart = chartAxis.getFillChart();

        fillChart.evaluatePrintWhenExpression(evaluation);
        if (!(fillChart.isPrintWhenExpressionNull() || fillChart.isPrintWhenTrue())) {
            continue;
        }

        axisNumber++;
        JFreeChart axisChart = fillChart.evaluateChart(evaluation);
        ChartHyperlinkProvider axisHyperlinkProvider = fillChart.getHyperlinkProvider();

        // In JFreeChart to add a second chart type to an existing chart
        // you need to add an axis, a data series and a renderer.  To
        // leverage existing code we simply create a new chart for the
        // axis and then pull out the bits we need and add them to the multi
        // chart.  Currently JFree only supports category plots and xy plots
        // in a multi-axis chart, and you can not mix the two.
        if (mainPlot instanceof CategoryPlot) {
            CategoryPlot mainCatPlot = (CategoryPlot) mainPlot;
            if (!(axisChart.getPlot() instanceof CategoryPlot)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_TYPES_MIX_NOT_ALLOWED,
                        (Object[]) null);
            }

            // Get the axis and add it to the multi axis chart plot
            CategoryPlot axisPlot = (CategoryPlot) axisChart.getPlot();
            mainCatPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis());
            mainCatPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(chartAxis));

            // Add the data set and map it to the recently added axis
            mainCatPlot.setDataset(axisNumber, axisPlot.getDataset());
            mainCatPlot.mapDatasetToRangeAxis(axisNumber, axisNumber);

            // Set the renderer to use to draw the dataset.
            mainCatPlot.setRenderer(axisNumber, axisPlot.getRenderer());

            // Handle any color series for this chart
            configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot());

            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(axisPlot.getDataset(), axisHyperlinkProvider);
            }
        } else if (mainPlot instanceof XYPlot) {
            XYPlot mainXyPlot = (XYPlot) mainPlot;
            if (!(axisChart.getPlot() instanceof XYPlot)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_TYPES_MIX_NOT_ALLOWED,
                        (Object[]) null);
            }

            // Get the axis and add it to the multi axis chart plot
            XYPlot axisPlot = (XYPlot) axisChart.getPlot();
            mainXyPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis());
            mainXyPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(chartAxis));

            // Add the data set and map it to the recently added axis
            mainXyPlot.setDataset(axisNumber, axisPlot.getDataset());
            mainXyPlot.mapDatasetToRangeAxis(axisNumber, axisNumber);

            // Set the renderer to use to draw the dataset.
            mainXyPlot.setRenderer(axisNumber, axisPlot.getRenderer());

            // Handle any color series for this chart
            configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot());

            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(axisPlot.getDataset(), axisHyperlinkProvider);
            }
        } else {
            throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_NOT_SUPPORTED, (Object[]) null);
        }
    }

    //set the multi hyperlink provider
    chartHyperlinkProvider = multiHyperlinkProvider;
}

From source file:sim.app.sugarscape.util.ResultsGrapher.java

JFreeChart createChart1(XYSeries[] series) {
    JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]),
            PlotOrientation.VERTICAL, true, true, false);
    //System.out.println("Series count = " +series[0].getItemCount());
    XYPlot plot = chart3.getXYPlot();

    ValueAxis yAxis = plot.getRangeAxis();
    //xAxis.setFixedDimension(100);
    //yAxis.setFixedDimension(1.0);
    //yAxis.setRange(0,1);
    ValueAxis xAxis = plot.getDomainAxis();
    //xAxis.setFixedDimension(50);

    StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
    renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20));
    renderer.setItemLabelsVisible(true);

    renderer.setSeriesItemLabelsVisible(1, true);
    renderer.setBaseShapesVisible(true);
    //XYLabelGenerator generator = new StandardXYLabelGenerator();

    //"{2}", new DecimalFormat("0.00") );
    //renderer.setLabelGenerator(generator);
    //NumberAxis axis2 = new NumberAxis("Average Agent Vision");
    //renderer.setItemLabelsVisible(true);
    //axis2.setAutoRangeIncludesZero(false);
    //axis2.setRange(0,12);
    //plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision);
    //plot.setDataset(1, vision);
    //String first_letter = x_param_fieldname.substring(0,1)+"=";
    XYSeriesCollection xys = new XYSeriesCollection();
    for (int a = 0; a < series.length; a++) {
        xys.addSeries(series[a]);//from w  ww .j  ava 2s  . c o m
        //xys.
        //xys.getSeriesName(4);
        System.out.println(xys.getSeries(a).getDescription());
    }
    plot.setDataset(0, xys);
    return chart3;

}

From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java

private void addDataset(String pId, XYDataset pDataset) {
    if (chart == null) {
        setupChart(pId, pDataset);/*w  w  w .j ava 2s  .  c om*/
    } else {
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setDataset(plot.getDatasetCount(), pDataset);
        NumberAxis axis = new NumberAxis(pId);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(0);
        nf.setMaximumFractionDigits(0);
        axis.setNumberFormatOverride(nf);
        plot.setRangeAxis(plot.getDatasetCount() - 1, axis);
        plot.setRangeAxisLocation(plot.getDatasetCount() - 1, AxisLocation.TOP_OR_LEFT);
        plot.mapDatasetToRangeAxis(plot.getDatasetCount() - 1, plot.getDatasetCount() - 1);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, jShowLines.isSelected());
        renderer.setSeriesShapesVisible(0, jShowDataPoints.isSelected());
        plot.setRenderer(plot.getDatasetCount() - 1, renderer);
        renderer.setDefaultItemLabelsVisible(jShowItemValues.isSelected());
        renderer.setDefaultItemLabelGenerator(new org.jfree.chart.labels.StandardXYItemLabelGenerator());
        renderer.setDefaultToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"), NumberFormat.getInstance()));
        axis.setAxisLinePaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint());
        axis.setLabelPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint());
        axis.setTickLabelPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint());
        axis.setTickMarkPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint());
    }
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.LogLinChartUIComponent.java

/***********************************************************************************************
 * Customise the XYPlot of a new chart, e.g. for fixed range axes.
 *
 * @param datasettype//from  www. j a  v  a2s .  c o m
 * @param primarydataset
 * @param secondarydatasets
 * @param updatetype
 * @param displaylimit
 * @param channelselector
 * @param debug
 *
 * @return JFreeChart
 */

public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset,
        final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit,
        final ChannelSelectorUIComponentInterface channelselector, final boolean debug) {
    final String SOURCE = "LogLinChartUIComponent.createCustomisedChart ";
    final JFreeChart jFreeChart;

    LOGGER.debug(debug, SOURCE + "--> ChartHelper.createChart()");

    MetadataHelper.showMetadataList(getMetadata(), SOURCE + " CHART METADATA --> ChartHelper.createChart()",
            LOADER_PROPERTIES.isMetadataDebug());

    channelselector.debugSelector(debug, SOURCE);

    // Creates TimeSeriesChart or XYLineChart to suit the dataset
    // The default renderer is an XYLineAndShapeRenderer
    jFreeChart = ChartHelper.createChart(primarydataset,
            ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug),
            getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit,
            channelselector, debug);
    if (jFreeChart != null) {
        // Customise the Chart for LogLin data if possible
        if ((hasLogarithmicMode()) && (!channelselector.isLinearMode())) {
            final XYPlot plot;
            final LogarithmicAxis axisLog;
            final String strAxisLabel;

            LOGGER.debug(debug, SOURCE + "Customise the Chart for LogLin data");

            // The set of Metadata available should include the Instrument
            // and any items from the current observation
            strAxisLabel = MetadataHelper.getMetadataValueByKey(getMetadata(),
                    MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey()
                            + MetadataDictionary.SUFFIX_SERIES_ZERO);

            // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis
            axisLog = new LogarithmicAxis(strAxisLabel);

            axisLog.setAllowNegativesFlag(true);
            axisLog.setLog10TickLabelsFlag(true);

            if ((canAutorange()) && (channelselector.isAutoranging())) {
                axisLog.setAutoRange(true);
                axisLog.configure();
                axisLog.autoAdjustRange();
            } else {
                axisLog.setRange(getLogarithmicFixedMinY(), getLogarithmicFixedMaxY());
                axisLog.configure();
                axisLog.autoAdjustRange();
            }

            plot = jFreeChart.getXYPlot();
            plot.setRangeAxis(INDEX_AXIS, axisLog);
            plot.setRangeAxisLocation(INDEX_AXIS, AxisLocation.BOTTOM_OR_LEFT);

            // Map the dataset to the axis
            plot.setDataset(INDEX_DATA, primarydataset);
            plot.mapDatasetToRangeAxis(INDEX_DATA, INDEX_AXIS);

            // Change the DateAxis format
            if (DatasetType.TIMESTAMPED.equals(datasettype)) {
                final DateAxis axisDate;

                // Customise the DomainAxis at index 0
                axisDate = (DateAxis) plot.getDomainAxis();

                // Showing the YYYY-MM-DD makes a very long label...
                axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
            }

            // Now customise the data renderer to improve legend visibility
            ChartUIHelper.customisePlotRenderer(plot, 0);
        } else {
            final XYPlot plot;

            LOGGER.debug(debug, SOURCE + "Customise the Chart for Linear data");

            // Linear Mode

            // A default range suitable for display of dB
            ChartHelper.handleAutorangeForLinearMode(jFreeChart, channelselector, canAutorange(),
                    getLinearFixedMinY(), getLinearFixedMaxY(), debug);

            // Now customise the data renderer to improve legend visibility
            plot = jFreeChart.getXYPlot();
            ChartUIHelper.customisePlotRenderer(plot, 0);
        }
    } else {
        LOGGER.debug(debug, SOURCE + "Chart is NULL");
    }

    return (jFreeChart);
}