Example usage for org.jfree.chart.axis NumberAxis setAutoRange

List of usage examples for org.jfree.chart.axis NumberAxis setAutoRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setAutoRange.

Prototype

public void setAutoRange(boolean auto) 

Source Link

Document

Sets a flag that determines whether or not the axis range is automatically adjusted to fit the data, and notifies registered listeners that the axis has been modified.

Usage

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  .ja 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.matsim.contrib.analysis.christoph.ActivitiesAnalyzer.java

@Override
public void notifyIterationEnds(IterationEndsEvent event) {

    OutputDirectoryHierarchy outputDirectoryHierarchy = event.getServices().getControlerIO();

    try {/*from w  w w  .  j  a va2  s  .co  m*/
        for (String activityType : this.activityCountData.keySet()) {
            String fileName = outputDirectoryHierarchy.getIterationFilename(event.getIteration(),
                    this.activitiesFileName + "_" + activityType + ".txt");
            BufferedWriter activitiesWriter = IOUtils.getBufferedWriter(fileName);

            activitiesWriter.write("TIME");
            activitiesWriter.write("\t");
            activitiesWriter.write(activityType.toUpperCase());
            activitiesWriter.write("\n");

            List<ActivityData> list = this.activityCountData.get(activityType);
            for (ActivityData activityData : list) {
                activitiesWriter.write(String.valueOf(activityData.time));
                activitiesWriter.write("\t");
                activitiesWriter.write(String.valueOf(activityData.activityCount));
                activitiesWriter.write("\n");
            }

            activitiesWriter.flush();
            activitiesWriter.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }

    if (this.createGraphs) {
        // create chart when data of more than one iteration is available.
        XYLineChart chart;

        /*
         * number of performed activities
         */
        chart = new XYLineChart("Number of performed Activities", "time", "# activities");
        for (String activityType : this.activityCountData.keySet()) {
            List<ActivityData> list = this.activityCountData.get(activityType);
            int length = list.size();

            double[] times = new double[length * 2 - 1];
            double[] counts = new double[length * 2 - 1];
            Iterator<ActivityData> iter = list.iterator();
            int i = 0;
            double lastValue = 0.0;
            while (iter.hasNext()) {
                ActivityData activityData = iter.next();
                times[i] = Math.min(activityData.time, this.endTime) / 3600.0;
                counts[i] = activityData.activityCount;
                if (i > 0) {
                    times[i - 1] = Math.min(activityData.time, this.endTime) / 3600.0;
                    counts[i - 1] = lastValue;
                }
                lastValue = activityData.activityCount;
                i += 2;
            }
            chart.addSeries(activityType, times, counts);
        }
        int length = this.overallCount.size();
        double[] times = new double[length * 2 - 1];
        double[] counts = new double[length * 2 - 1];
        Iterator<ActivityData> iter = this.overallCount.iterator();
        int i = 0;
        double lastValue = 0.0;
        while (iter.hasNext()) {
            ActivityData activityData = iter.next();
            times[i] = Math.min(activityData.time, this.endTime) / 3600.0;
            counts[i] = activityData.activityCount;
            if (i > 0) {
                times[i - 1] = Math.min(activityData.time, this.endTime) / 3600.0;
                counts[i - 1] = lastValue;
            }
            lastValue = activityData.activityCount;
            i += 2;
        }
        chart.addSeries("overall", times, counts);

        NumberAxis domainAxis = (NumberAxis) chart.getChart().getXYPlot().getDomainAxis();
        domainAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 11));
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        domainAxis.setAutoRange(false);
        domainAxis.setRange(0, endTime / 3600.0);

        chart.addMatsimLogo();
        String fileName = outputDirectoryHierarchy.getIterationFilename(event.getIteration(),
                this.activitiesFileName + ".png");
        chart.saveAsPng(fileName, 800, 600);
    }
}

From source file:org.jls.toolbox.math.chart.XYLineChart.java

/**
 * Permet de paramtrer le graphique une fois cr.
 *//* w ww.  j  a v  a2  s . c o  m*/
private void setChartStyle() {
    // Paramtrage des courbes
    this.plot.setBackgroundAlpha((float) 0.0);
    this.plot.setDomainCrosshairVisible(this.isGridXVisible);
    this.plot.setDomainCrosshairLockedOnData(true);
    this.plot.setRangeCrosshairVisible(this.isGridYVisible);
    this.plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    this.plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    NumberAxis xAxis = (NumberAxis) this.plot.getDomainAxis();
    NumberAxis yAxis = (NumberAxis) this.plot.getRangeAxis();

    this.chart.setBackgroundPaint(this.CHART_BACKGROUND_COLOR);
    xAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(false);

    yAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(false);

    this.plot.setBackgroundPaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setRangeGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainCrosshairPaint(this.CROSSHAIR_COLOR);
    this.plot.setRangeCrosshairPaint(this.CROSSHAIR_COLOR);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) this.plot.getRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
}

From source file:jesse.GA_ANN.DataVis.java

JFreeChart createChart()//Here Input MillSecond
{
    total = new XYSeries[10];
    XYSeriescollection = new XYSeriesCollection();
    for (int i = 0; i < 10; i++) {
        total[i] = new XYSeries(i);
        XYSeriescollection.addSeries(total[i]);
    }//from   w ww.j  a va  2s .  co  m

    dateaxis = new NumberAxis("Time");
    NumberAxis Conaxis = new NumberAxis("z??");
    dateaxis.setAutoRange(true);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.green);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1F, 0, 2));
    xylineandshaperenderer.setFillPaint(new Color(30, 30, 220), true);

    Conaxis.setRange(-1, 1);
    Conaxis.setAutoRange(true);
    Conaxis.setAutoRangeIncludesZero(false);

    XYPlot xyplot = new XYPlot(XYSeriescollection, dateaxis, Conaxis, xylineandshaperenderer);
    JFreeChart jfreechart = new JFreeChart("time-z", new Font("Arial", 1, 24), xyplot, true);
    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart, true);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    return jfreechart;
}

From source file:org.jls.toolbox.math.chart.XYBlockChart.java

/**
 * Permet de paramtrer le graphique une fois cr.
 *//*from  ww  w.j a  v  a2s . com*/
private void setChartStyle() {
    this.plot.setBackgroundAlpha((float) 0.0);
    this.plot.setDomainCrosshairLockedOnData(false);
    this.plot.setRangeCrosshairLockedOnData(false);
    this.plot.setDomainCrosshairVisible(true);
    this.plot.setRangeCrosshairVisible(true);
    this.plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    this.plot.setDomainGridlinesVisible(true);
    this.plot.setRangeGridlinesVisible(true);
    this.plot.setRangeGridlinePaint(Color.white);

    this.plot.setDomainCrosshairStroke(new BasicStroke(1f));
    this.plot.setRangeCrosshairStroke(new BasicStroke(1f));
    this.chart.setBackgroundPaint(this.CHART_BACKGROUND_COLOR);

    NumberAxis xAxis = (NumberAxis) this.plot.getDomainAxis();
    NumberAxis yAxis = (NumberAxis) this.plot.getRangeAxis();

    xAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(false);

    yAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(false);

    this.plot.setBackgroundPaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setRangeGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainCrosshairPaint(this.CROSSHAIR_COLOR);
    this.plot.setRangeCrosshairPaint(this.CROSSHAIR_COLOR);
}

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

private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//from w w w .j  a v a  2  s  . c o  m

    chart.setBackgroundPaint(Color.white);

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

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
        if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            chart.getXYPlot().setDomainAxis(domainAxis);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) {
        xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    } else {
        xAxis.setLabel(SERIESINDEX_LABEL);
    }
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
        if (getRangeForDimension(indexAxis) != null) {
            xAxis.setRange(getRangeForDimension(indexAxis));
        }
    } else {
        if (getRangeForName(SERIESINDEX_LABEL) != null) {
            xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
        }
    }

    // renderer and range axis
    synchronized (dataTable) {
        int numberOfSelectedColumns = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    numberOfSelectedColumns++;
                }
            }
        }

        int columnCount = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    // YIntervalSeries series = new
                    // YIntervalSeries(this.dataTable.getColumnName(c));
                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries(dataTable.getColumnName(c));
                    Iterator<DataTableRow> i = dataTable.iterator();
                    int index = 1;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(c);

                        if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                            double indexValue = row.getValue(indexAxis);
                            series.add(indexValue, value);
                        } else {
                            series.add(index++, value);
                        }
                    }
                    dataset.addSeries(series);

                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

                    Color color = getColorProvider().getPointColor(1.0d);
                    if (numberOfSelectedColumns > 1) {
                        color = getColorProvider()
                                .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
                    }
                    renderer.setSeriesPaint(0, color);
                    renderer.setSeriesStroke(0,
                            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                    renderer.setSeriesShapesVisible(0, false);

                    NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
                    if (getRangeForDimension(c) != null) {
                        yAxis.setRange(getRangeForDimension(c));
                    } else {
                        yAxis.setAutoRange(true);
                        yAxis.setAutoRangeStickyZero(false);
                        yAxis.setAutoRangeIncludesZero(false);
                    }
                    yAxis.setLabelFont(LABEL_FONT_BOLD);
                    yAxis.setTickLabelFont(LABEL_FONT);
                    if (numberOfSelectedColumns > 1) {
                        yAxis.setAxisLinePaint(color);
                        yAxis.setTickMarkPaint(color);
                        yAxis.setLabelPaint(color);
                        yAxis.setTickLabelPaint(color);
                    }

                    plot.setRangeAxis(columnCount, yAxis);
                    plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

                    plot.setDataset(columnCount, dataset);
                    plot.setRenderer(columnCount, renderer);
                    plot.mapDatasetToRangeAxis(columnCount, columnCount);

                    columnCount++;
                }
            }
        }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart.//  w  ww  .j  a  v a 2s  .c  o m
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

From source file:MWC.GUI.JFreeChart.StepperXYPlot.java

/**
 * Draws the XY plot on a Java 2D graphics device (such as the screen or a
 * printer), together with a current time marker
 * <P>/*ww w . ja  v  a2  s  . com*/
 * XYPlot relies on an XYItemRenderer to draw each item in the plot. This
 * allows the visual representation of the data to be changed easily.
 * <P>
 * The optional info argument collects information about the rendering of the
 * plot (dimensions, tooltip information etc). Just pass in null if you do not
 * need this information.
 * 
 * @param g2
 *          The graphics device.
 * @param plotArea
 *          The area within which the plot (including axis labels) should be
 *          drawn.
 * @param info
 *          Collects chart drawing information (null permitted).
 */
public final void draw(final Graphics2D g2, final Rectangle2D plotArea, final Point2D anchor,
        final PlotState state, final PlotRenderingInfo info) {
    super.draw(g2, plotArea, anchor, state, info);

    // do we want to view the line?
    if (!_showLine)
        return;

    // do we have a time?
    if (_currentTime != null) {
        // find the screen area for the dataset
        final Rectangle2D dataArea = info.getDataArea();

        // determine the time we are plotting the line at
        long theTime = _currentTime.getMicros();

        // hmmm, how do we format the date
        final CanBeRelativeToTimeStepper axis = (CanBeRelativeToTimeStepper) this.getDomainAxis();

        // are we working in relative time mode?
        if (axis.isRelativeTimes()) {
            if (_myStepper != null) {
                // yes, we now need to offset the time
                theTime = theTime - _myStepper.getTimeZero().getMicros();
            }
        }

        // hmm, see if we are wroking with a date or number axis
        double linePosition = 0;
        if (axis instanceof DateAxis) {
            // ok, now scale the time to graph units
            final DateAxis dateAxis = (DateAxis) axis;

            // find the new x value
            linePosition = dateAxis.dateToJava2D(new Date(theTime / 1000), dataArea, this.getDomainAxisEdge());

            if (_resetAxes) {
                dateAxis.setAutoRange(true);
                _resetAxes = false;
            }

            if (isGrowWithTime()) {
                final long endMillis = theTime / 1000;
                long startMillis;

                if (_fixedDuration != null) {
                    startMillis = endMillis - _fixedDuration.getMillis();
                } else {
                    startMillis = (long) dateAxis.getLowerBound();
                }

                final Date startDate = new Date(startMillis);
                final Date endDate = new Date(endMillis);

                dateAxis.setRange(startDate, endDate);
            } else {
            }

        } else {
            if (axis instanceof NumberAxis) {
                final NumberAxis numberAxis = (NumberAxis) axis;
                linePosition = numberAxis.valueToJava2D(theTime, dataArea, this.getDomainAxisEdge());

                if (isGrowWithTime())
                    numberAxis.setRange(numberAxis.getRange().getLowerBound(), theTime);
                else {
                    if (_resetAxes) {
                        numberAxis.setAutoRange(true);
                        _resetAxes = false;
                    }
                }

            }
        }

        // ok, finally draw the line - if we're not showing the growing plot
        if (!isGrowWithTime())
            plotStepperLine(g2, linePosition, dataArea);

    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * //from www.j a  v a  2s .  c  o  m
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (xLowerBound != null && xUpperBound != null) {
        xAxis.setLowerBound(xLowerBound);
        xAxis.setUpperBound(xUpperBound);
    } else {
        xAxis.setAutoRange(true);
    }
    xAxis.setAxisLinePaint(Color.white);
    xAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (yLowerBound != null && yUpperBound != null) {
        yAxis.setLowerBound(yLowerBound);
        yAxis.setUpperBound(yUpperBound);
    } else
        yAxis.setAutoRange(true);

    yAxis.setAxisLinePaint(Color.white);
    yAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale paintScale = null;

    if (grayPaintScale) {
        paintScale = new GrayPaintScale(minScaleValue, maxScaleValue);
    } else {
        if (scaleLowerBound != null && scaleUpperBound != null) {
            paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray);
        } else {
            paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray);
        }
        for (int i = 0; i < zRangeArray.length; i++) {
            ZRange zRange = zRangeArray[i];
            ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor());

        }
    }

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setForegroundAlpha(0.66f);

    chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    chart.removeLegend();

    NumberAxis scaleAxis = new NumberAxis(zLabel);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    if (scaleLowerBound != null && scaleUpperBound != null) {
        scaleAxis.setLowerBound(scaleLowerBound);
        scaleAxis.setUpperBound(scaleUpperBound);
    } else
        scaleAxis.setAutoRange(true);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        scaleAxis.setLabelFont(addLabelsStyle.getFont());
        scaleAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    if (blockHeight != null && blockWidth != null) {
        renderer.setBlockWidth(blockWidth.doubleValue());
        renderer.setBlockHeight(blockHeight.doubleValue());
    }

    PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.black));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(color);

    chart.addSubtitle(legend);

    //      chart.setBackgroundPaint(new Color(180, 180, 250));   
    chart.setBackgroundPaint(color);

    logger.debug("OUT");
    return chart;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHistogram.java

@Override
protected void resetSerie(final IScope scope, final String serieid) {
    // TODO Auto-generated method stub

    final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid);
    // DefaultCategoryDataset serie=((DefaultCategoryDataset)
    // jfreedataset.get(IdPosition.get(dataserie.getSerieId(scope))));
    final DefaultCategoryDataset serie = (DefaultCategoryDataset) jfreedataset.get(0);
    if (serie.getRowKeys().contains(serieid)) {
        serie.removeRow(serieid);/*from  www.j a v  a 2  s.c o m*/
    }
    final ArrayList<String> CValues = dataserie.getCValues(scope);
    final ArrayList<Double> YValues = dataserie.getYValues(scope);
    final ArrayList<Double> SValues = dataserie.getSValues(scope);
    if (CValues.size() > 0) {
        // TODO Hack to speed up, change!!!
        // final CategoryAxis domainAxis = ((CategoryPlot)
        // this.chart.getPlot()).getDomainAxis();
        final NumberAxis rangeAxis = (NumberAxis) ((CategoryPlot) this.chart.getPlot()).getRangeAxis();
        rangeAxis.setAutoRange(false);
        for (int i = 0; i < CValues.size(); i++) {
            if (getY_LogScale(scope)) {
                final double val = YValues.get(i);
                if (val <= 0) {
                    throw GamaRuntimeException.warning("Log scale with <=0 value:" + val, scope);
                } else {
                    serie.addValue(YValues.get(i), serieid, CValues.get(i));
                }

            } else {
                serie.addValue(YValues.get(i), serieid, CValues.get(i));

            }
            // ((ExtendedCategoryAxis)domainAxis).addSubLabel(CValues.get(i),
            // serieid);;
        }
    }
    if (SValues.size() > 0) {
        // what to do with Z values??

    }

    this.resetRenderer(scope, serieid);

}