Example usage for org.jfree.chart.axis ValueAxis setLabelFont

List of usage examples for org.jfree.chart.axis ValueAxis setLabelFont

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis setLabelFont.

Prototype

public void setLabelFont(Font font) 

Source Link

Document

Sets the font for the axis label and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.toobsframework.pres.chart.ChartBuilder.java

public ValueAxis createValueAxis(IRequest componentRequest, RangeAxisDef valueAxisDef, Map params,
        boolean is3D) {
    ValueAxis valueAxis;
    if (is3D) {// ww w.j  a v  a2s. co  m
        valueAxis = new NumberAxis3D();
    } else {
        valueAxis = new NumberAxis();
    }
    if (valueAxisDef != null) {
        if (valueAxisDef.getRangeLabel() != null) {
            valueAxis.setLabel(
                    ChartUtil.evaluateTextLabel(componentRequest, valueAxisDef.getRangeLabel(), params));
            if (valueAxisDef.getRangeLabel().getFont() != null) {
                valueAxis.setLabelFont(ChartUtil.getFont(valueAxisDef.getRangeLabel(), null));
            }
            valueAxis.setLabelPaint(ChartUtil.getColor(valueAxisDef.getRangeLabel().getColor()));
        }
        if (valueAxisDef.getIntegerTicks()) {
            valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        }
        if (valueAxisDef.getNumberFormater() != null) {
            switch (valueAxisDef.getNumberFormater().getType()) {
            case AxisDefNumberFormaterType.PERCENT_TYPE:
                ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getPercentInstance());
                break;
            case AxisDefNumberFormaterType.CUSTOMBEAN_TYPE:
                ((NumberAxis) valueAxis).setNumberFormatOverride(
                        (NumberFormat) beanFactory.getBean(valueAxisDef.getCustomFormatBean()));

                break;
            }
        }
    }
    return valueAxis;
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

/**
 * ?jfreechart/*from w  ww  .  j av  a  2s. co m*/
 */
public void initChart() {
    ts_LP = new TimeSeries("LowPressure", Millisecond.class);
    ts_HP = new TimeSeries("HighPressure", Millisecond.class);
    ts_humidity = new TimeSeries("Humidity", Millisecond.class);
    ts_temprature = new TimeSeries("Temperature", Millisecond.class);
    ts_time = new TimeSeries("TestTime", Millisecond.class);
    ts_num = new TimeSeries("num", Millisecond.class);
    ts_reserved1 = new TimeSeries("reserved1", Millisecond.class);
    ts_reserved2 = new TimeSeries("reserved2", Millisecond.class);
    ts_reserved3 = new TimeSeries("reserved3", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_LP);

    trcollection.addSeries(ts_HP);

    trcollection2 = new TimeSeriesCollection(ts_humidity);

    trcollection2.addSeries(ts_temprature);

    //        trcollection2.addSeries(ts_num);
    //        trcollection2.addSeries(ts_time);
    //trcollection2.addSeries(ts_reserved1);
    //trcollection2.addSeries(ts_reserved2);
    //trcollection2.addSeries(ts_reserved3);

    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.cyan);
    line1render.setSeriesPaint(1, Rosered);
    line1render.setSeriesPaint(2, Color.orange);
    line1render.setSeriesPaint(3, Color.yellow);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }/* w  w  w . j  a v  a2  s .c o m*/
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * some jFreeChart Axis settings for TimeValueDiagram
 * @param plot            jFreeChart plot instance
 * @param rangeAxisLabel   Label of rangeAxis
 *//*  ww w .  j  ava 2  s  .c o  m*/
private void buildTimeValueDiagramAxisFormat(XYPlot plot, String rangeAxisLabel) {
    System.out.println("StatisticGrafic.buildTimeValueDiagramAxisFormat");
    ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis();
    double a = 0.1 * Math.max(Math.abs(statistic.getValueLow()), Math.abs(statistic.getValueHigh()));
    rangeAxis.setLowerBound(statistic.getValueLow() - a);
    rangeAxis.setUpperBound(statistic.getValueHigh() + a);
    rangeAxis.setLabel(rangeAxisLabel);
    rangeAxis.setLabelFont(FONT_DEFAULT);

    DateAxis dateAxis = new DateAxis();
    DateAxis[] domainAxisArray = new DateAxis[1];
    domainAxisArray[0] = dateAxis;
    plot.setDomainAxes(domainAxisArray);

    dateAxis.setLowerBound(statistic.getTimeLow());
    dateAxis.setUpperBound(statistic.getTimeHigh());

    long diff = statistic.getTimeHigh() - statistic.getTimeLow();
    String format, unit;
    if (diff > 24 * 60 * 60 * 1000) {
        format = "d.MM.yyyy";
        unit = "[day]";
    } else if (diff > 60 * 60 * 1000) {
        format = "H:mm";
        unit = "[h]";
    } else if (diff > 60 * 1000) {
        format = "m:ss";
        unit = "[min]";
    } else if (diff > 1000) {
        format = "s.S";
        unit = "[sec]";
    } else {
        format = "S";
        unit = "[millisec]";
    }
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    dateAxis.setDateFormatOverride(sdf);
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS");
    String von = sdf1.format(dateAxis.getMinimumDate());
    String bis = sdf1.format(dateAxis.getMaximumDate());
    dateAxis.setLabel(von + "    Time " + unit + "   " + bis);
    dateAxis.setLabelFont(FONT_DEFAULT);

}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    String secondValueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    PlotOrientation orientation = chartDefinition.getOrientation();

    // split BarLineChartDefinition in two Definitions
    CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition(
            chartDefinition.getSession(), chartDefinition.getChartAttributes());
    CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition(
            chartDefinition.getSession(), chartDefinition.getChartAttributes());

    /*/*from  w w  w.  j  a v a  2 s  . c  o  m*/
     * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset =
     * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){}
     */

    // get column and row count of the data set
    int iColumnCount = chartDefinition.getColumnCount();
    int iRowCount = chartDefinition.getRowCount();

    if (iRowCount <= 0) {
        chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$
    }

    /*
     * Copy data to the two new data sets
     */
    // Loop through columns
    for (int r = 0; r < iRowCount; r++) {

        // check if measure should be include in bar or line dataset
        String strMeasureName = (String) chartDefinition.getRowKey(r);
        boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName);
        boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName);

        // getting all values
        for (int c = 0; c < iColumnCount; c++) {
            Comparable compColumnName = chartDefinition.getColumnKey(c);
            Number nValue = chartDefinition.getValue(strMeasureName, compColumnName);
            if (bIsBarColumn) {
                barsDataset.addValue(nValue, strMeasureName, compColumnName);
            }
            if (bIsLineColumn) {
                linesDataset.addValue(nValue, strMeasureName, compColumnName);
            }
        }

    }

    if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) {
        chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$
    }

    // Create Axis Objects
    CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis barsAxis = new NumberAxis(valueAxisLabel);
    NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel);

    // set title and font for lines Axis
    linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle());
    linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont());
    if (chartDefinition.getLinesRangeTickFormat() != null) {
        linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat());
    }

    // create renderer
    BarRenderer barRenderer = null;
    LineAndShapeRenderer lineRenderer = null;
    // Determine the type of renderer to use
    if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
        if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
            barRenderer = new StackedBarRenderer3D();
            lineRenderer = new LineRenderer3D();
        } else if (chartDefinition.isStacked()) {
            barRenderer = new StackedBarRenderer();
            lineRenderer = new LineAndShapeRenderer();
        } else {
            barRenderer = new BarRenderer3D();
            lineRenderer = new LineRenderer3D();
        }
    } else {
        barRenderer = new BarRenderer();
        lineRenderer = new LineAndShapeRenderer();
    }
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
        barRenderer.setPositiveItemLabelPosition(position1);
        lineRenderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
        barRenderer.setNegativeItemLabelPosition(position2);
        lineRenderer.setNegativeItemLabelPosition(position2);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BOTTOM_CENTER);
        barRenderer.setPositiveItemLabelPosition(position1);
        lineRenderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
        barRenderer.setNegativeItemLabelPosition(position2);
        lineRenderer.setNegativeItemLabelPosition(position2);
    }
    if (tooltips) {
        barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
        lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    if (chartDefinition.getMaxBarWidth() != null) {
        barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
    }

    // setting some line attributes
    lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(),
            chartDefinition.getLineWidth()));
    lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible());
    lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());

    /*
     * Create plot and make necessary adjustments for overlaid chart
     */
    // create the plot with bar chart
    CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer);
    // add line renderer
    plot.setRenderer(1, lineRenderer);
    // add lines dataset, renderer and axis to plot
    plot.setDataset(1, linesDataset);
    plot.setRangeAxis(1, linesAxis);
    // map lines to second axis
    plot.mapDatasetToRangeAxis(1, 1);
    // set rendering order
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // set location of second axis
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    // standard settings for plots
    JFreeChartEngine.updatePlot(plot, barsDataset);
    // additional settings for second axis
    ValueAxis secondValueAxis = plot.getRangeAxis(1);

    if (secondValueAxis != null) {
        if (chartDefinition.getLinesRangeTitle() != null) {
            secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle());
        }
        if (chartDefinition.getLinesRangeTitleFont() != null) {
            secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont());
        }
        if (chartDefinition.getLinesRangeTickFont() != null) {
            secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont());
        }
        if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
            secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum());
        }
        if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
            secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum());
        }
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;
}

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

@Override
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);
    CategoryDataset dataset = makeDataSet();

    chart = createChart(title, xLabel, yLabel, dataset, false, false);

    // start customizing the graph
    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET);
    Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class,
            backgroundColor);//  w w  w . j  a v a2 s .co  m
    Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class,
            backgroundColor);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);

    chart.setBackgroundPaint(backgroundColor);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset));
    plot.setDomainGridlinePaint(graphDomainGridlinePaint);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(graphRangeGridlinePaint);
    plot.setOutlineVisible(graphBorder);

    // set the axis location
    AxisLocation axisLocation = getParam(GraphSource.GRAPH_RANGE_AXIS_LOCATION, AxisLocation.class,
            AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(axisLocation);

    // customize the y-axis
    if (params.get(RANGE_AXIS) instanceof ValueAxis) {
        ValueAxis valueAxis = (ValueAxis) params.get(RANGE_AXIS);
        plot.setRangeAxis(valueAxis);
    }

    ValueAxis valueAxis = plot.getRangeAxis();
    Object yAxisFont = params.get(GraphSource.GRAPH_Y_AXIS_FONT);
    Object yAxisLabelFont = params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT);
    Double rangeLowerBound = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, null);
    Double rangeUpperBound = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, null);
    boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false);
    boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class,
            true);

    if (yAxisFont instanceof Font) {
        valueAxis.setTickLabelFont((Font) yAxisFont);
    }

    if (yAxisLabelFont instanceof Font) {
        valueAxis.setLabelFont((Font) yAxisLabelFont);
    }

    if (rangeLowerBound != null) {
        valueAxis.setLowerBound(rangeLowerBound);
    }

    if (rangeUpperBound != null) {
        valueAxis.setUpperBound(rangeUpperBound);
    }

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

    valueAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible);

    // customize the x-axis
    if (params.get(DOMAIN_AXIS) instanceof CategoryAxis) {
        CategoryAxis domainAxis = (CategoryAxis) params.get(DOMAIN_AXIS);
        plot.setDomainAxis(domainAxis);
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    Object xAxisFont = params.get(GraphSource.GRAPH_X_AXIS_FONT);
    Object xAxisLabelFont = params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT);

    if (xAxisFont instanceof Font) {
        domainAxis.setTickLabelFont((Font) xAxisFont);
    }

    if (xAxisLabelFont instanceof Font) {
        domainAxis.setLabelFont((Font) xAxisLabelFont);
    }

    domainAxis.setLabel(xLabel);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);

    // change the font of the graph title
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    TextTitle textTitle = new TextTitle();
    textTitle.setText(title);
    textTitle.setFont(titleFont);
    chart.setTitle(textTitle);

    // makes a wrapper for the legend to remove the border around it
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    Object legendFont = params.get(GraphSource.LEGEND_FONT);

    if (legend) {
        LegendTitle legendTitle = 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 = legendTitle.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legendTitle.setWrapper(wrapper);
        legendTitle.setPosition(RectangleEdge.BOTTOM);
        legendTitle.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (legendFont instanceof Font) {
            legendTitle.setItemFont((Font) legendFont);
        }

        chart.addSubtitle(legendTitle);
    }

    this.initialized = true;
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

/**
 * ?jfreechart//from w w w . j a  v a 2s.  co m
 */
public void initChart() {
    ts_wppm = new TimeSeries("PPM", Millisecond.class);
    ts_wppm_zero = new TimeSeries("PPM-Zero", Millisecond.class);
    ts_flux = new TimeSeries("Flux", Millisecond.class);
    ts_wvtr = new TimeSeries("WVTR", Millisecond.class);
    ts_tempcell = new TimeSeries(" Cell Temperature", Millisecond.class);
    ts_tempambi = new TimeSeries("Ambient Temperature", Millisecond.class);
    ts_status = new TimeSeries("Status", Millisecond.class);
    ts_fitting = new TimeSeries("fitting curve1", Millisecond.class);
    ts_fitting2 = new TimeSeries("fitting curve2", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_wppm);

    trcollection.addSeries(ts_wppm_zero);

    trcollection.addSeries(ts_wvtr);

    trcollection.addSeries(ts_fitting2);//ppm
    trcollection2 = new TimeSeriesCollection(ts_flux);

    trcollection2.addSeries(ts_fitting);//temp3

    trcollection2.addSeries(ts_tempcell);

    trcollection2.addSeries(ts_tempambi);

    trcollection2.addSeries(ts_status);
    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.orange);
    line1render.setSeriesPaint(1, Color.yellow);
    line1render.setSeriesPaint(2, Color.cyan);
    line1render.setSeriesPaint(3, Rosered);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

private void initCategoryPlot(JFreeChart chart, ChartModel chartModel,
        final IChartLinkGenerator linkGenerator) {
    initPlot(chart, chartModel);/* w w  w  .  ja  va  2s  .c om*/

    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();
    CategoryPlot categoryPlot = chart.getCategoryPlot();

    Grid grid = twoAxisPlot.getGrid();
    if (twoAxisPlot.getOrientation() != Orientation.HORIZONTAL) {
        Color color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setDomainGridlinesVisible(grid.getVerticalLinesVisible());
        categoryPlot.setDomainGridlinePaint(color);

        color = (grid.getHorizontalLineColor() != null ? new Color(0x00FFFFFF & grid.getHorizontalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setRangeGridlinesVisible(grid.getHorizontalLinesVisible());
        categoryPlot.setRangeGridlinePaint(color);
    } else {
        Color color = (grid.getHorizontalLineColor() != null
                ? new Color(0x00FFFFFF & grid.getHorizontalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setDomainGridlinesVisible(grid.getHorizontalLinesVisible());
        categoryPlot.setDomainGridlinePaint(color);

        color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setRangeGridlinesVisible(grid.getVerticalLinesVisible());
        categoryPlot.setRangeGridlinePaint(color);
    }

    categoryPlot.setDomainGridlineStroke(new BasicStroke(1));
    categoryPlot.setRangeGridlineStroke(new BasicStroke(1));

    List<Integer> colors = getPlotColors(twoAxisPlot);

    for (int j = 0; j < categoryPlot.getDatasetCount(); j++) {
        if (linkGenerator != null) {
            categoryPlot.getRenderer(j).setBaseItemURLGenerator(new CategoryURLGenerator() {
                public String generateURL(CategoryDataset dataset, int series, int category) {
                    return linkGenerator.generateLink(dataset.getRowKey(series).toString(),
                            dataset.getColumnKey(category).toString(), dataset.getValue(series, category));
                }
            });
        }
        for (int i = 0; i < colors.size(); i++) {
            categoryPlot.getRenderer(j).setSeriesPaint(i, new Color(0x00FFFFFF & colors.get(i)));
        }
    }

    Font domainAxisFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getFontFamily(),
            twoAxisPlot.getDomainAxis().getFontStyle(), twoAxisPlot.getDomainAxis().getFontWeight(),
            twoAxisPlot.getDomainAxis().getFontSize());
    Font rangeAxisFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getFontFamily(),
            twoAxisPlot.getRangeAxis().getFontStyle(), twoAxisPlot.getRangeAxis().getFontWeight(),
            twoAxisPlot.getRangeAxis().getFontSize());
    Font rangeTitleFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getLegend().getFontFamily(),
            twoAxisPlot.getRangeAxis().getLegend().getFontStyle(),
            twoAxisPlot.getRangeAxis().getLegend().getFontWeight(),
            twoAxisPlot.getRangeAxis().getLegend().getFontSize());
    Font domainTitleFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getLegend().getFontFamily(),
            twoAxisPlot.getDomainAxis().getLegend().getFontStyle(),
            twoAxisPlot.getDomainAxis().getLegend().getFontWeight(),
            twoAxisPlot.getDomainAxis().getLegend().getFontSize());

    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();

    AxesLabels axesLabels = getAxesLabels(chartModel);
    if ((axesLabels.rangeAxisLabel.length() > 0) && (rangeTitleFont != null)) {
        rangeAxis.setLabelFont(rangeTitleFont);
    }

    if ((axesLabels.domainAxisLabel.length() > 0) && (domainTitleFont != null)) {
        domainAxis.setLabelFont(domainTitleFont);
    }

    LabelOrientation labelOrientation = twoAxisPlot.getHorizontalAxis().getLabelOrientation();
    if ((labelOrientation != null) && (labelOrientation != LabelOrientation.HORIZONTAL)) {
        if (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL) {
            if (labelOrientation == LabelOrientation.VERTICAL) {
                rangeAxis.setVerticalTickLabels(true);
            }
        } else {
            switch (labelOrientation) {
            case VERTICAL:
                domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
                break;
            case DIAGONAL:
                domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                break;
            }
        }
    }

    if (domainAxisFont != null) {
        domainAxis.setTickLabelFont(domainAxisFont);
    }
    if (rangeAxisFont != null) {
        rangeAxis.setTickLabelFont(rangeAxisFont);
    }

    Number rangeMin = twoAxisPlot.getRangeAxis().getMinValue();
    if (rangeMin != null) {
        rangeAxis.setLowerBound(rangeMin.doubleValue());
    }
    Number rangeMax = twoAxisPlot.getRangeAxis().getMaxValue();
    if (rangeMax != null) {
        rangeAxis.setUpperBound(rangeMax.doubleValue());
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void setAxesFont(Font axesFont) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        Plot plot = chart.getPlot();//from   w w w.  j a v a2  s. c  o  m

        if (plot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) plot;

            // first change range axes font
            int rangeAxisCount = categoryPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis valueAxis = categoryPlot.getRangeAxis(i);
                if (valueAxis != null) {
                    valueAxis.setLabelFont(axesFont);
                    valueAxis.setTickLabelFont(axesFont);
                }
            }

            // then set domain axis font
            CategoryAxis domainAxis = categoryPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabelFont(axesFont);
                domainAxis.setTickLabelFont(axesFont);
            }

        } else {
            XYPlot xyPlot = (XYPlot) plot;

            // first change range axes font
            int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < rangeAxisCount; ++i) {
                ValueAxis rangeAxis = xyPlot.getRangeAxis(i);
                if (rangeAxis != null) {
                    rangeAxis.setLabelFont(axesFont);
                    rangeAxis.setTickLabelFont(axesFont);
                }
            }

            // then set domain axis font
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabelFont(axesFont);
                domainAxis.setTickLabelFont(axesFont);
            }

        }
    }
}

From source file:windows.sensorWindow.java

/**
 * window constructor for chart window//from  w w  w  .  ja va 2 s.  c om
 * 
 * @param title
 *            title for the new window
 */
public sensorWindow(final String title) {

    super(title);

    System.out.println("create sensorWindow");

    // font customizing
    // -------------------------------------------------------
    /*
     * Font font1 = null; try { font1 = Font.createFont(Font.TRUETYPE_FONT,
     * new File("U:/workspace/SWTtest/fonts/roboto/Roboto-Black.ttf")); }
     * catch (FontFormatException | IOException e1) { e1.printStackTrace();
     * } StandardChartTheme chartTheme = new
     * StandardChartTheme("robotTheme");
     * chartTheme.setExtraLargeFont(font1.deriveFont(24f));
     * chartTheme.setLargeFont(font1.deriveFont(16f));
     * chartTheme.setRegularFont(font1.deriveFont(12f));
     * chartTheme.setSmallFont(font1.deriveFont(10f));
     * ChartFactory.setChartTheme(chartTheme);
     */
    Font font1 = new Font("Tahoma", Font.BOLD, 16);
    Font font2 = new Font("Tahoma", Font.PLAIN, 12);
    Font font3 = new Font("Tahoma", Font.BOLD, 16);
    customFonts.put("axisLabelFont", font1);
    customFonts.put("axisValueFont", font2);
    customFonts.put("titleFont", font3);
    // -------------------------------------------------------------------------

    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    plot = new CombinedDomainXYPlot(new DateAxis("Time"));

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        Brick tmpBrick = connectionData.presentedBrickList.get(i);
        addPlot(tmpBrick);
    }

    final JFreeChart chart = new JFreeChart("", plot);
    // chart.setBorderPaint(Color.black);
    // chart.setBorderVisible(true);
    // chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setRenderer(renderer2);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(chartRangeSec * 1000); // chart range seconds
    axis.setLabelFont(customFonts.get("axisLabelFont"));
    axis.setTickLabelFont(customFonts.get("axisValueFont"));

    //final JPanel content = new JPanel(new BorderLayout());
    content = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane();
    JViewport viewport = scrollPane.getViewport();
    viewport.setView(content);

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel, BorderLayout.NORTH);
    // content.add(getScrollBar(xAxe), BorderLayout.SOUTH);

    // disable zoom
    chartPanel.setRangeZoomable(false);
    chartPanel.setDomainZoomable(false);

    // mouse selection
    chartPanel.addMouseListener(new MouseMarker(chartPanel));

    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    // chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    // setContentPane(content);

    // ===================================================
    // buttons
    buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        for (int i2 = 0; i2 < 2; i2++) {
            Brick tmpBrick = connectionData.presentedBrickList.get(i);
            JButton button = new JButton(tmpBrick.uid + " start");
            button.setActionCommand(buttonComAddBtn + tmpBrick.uid + i + "(" + i2 + ")");
            button.addActionListener(this);
            tmplButtons.put(tmpBrick.uid, button);
            // if ((tmpBrick.ctrlTmpl[0]) || (tmpBrick.ctrlTmpl[1]))
            // {
            // buttonPanel.add(button);
            // }
            changeTmplCntrl(tmpBrick, i2);
        }
    }
    content.add(buttonPanel, BorderLayout.SOUTH);
    // ===================================================

    // ===================================================
    // scroll bar
    final JPanel sliderPanel = new JPanel(new FlowLayout());

    slider = new JSlider(1, sliderValuesNumber);
    slider.setValue(sliderValuesNumber);
    slider.setEnabled(false);
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (sliderData.sliderActive == true) {
                int sliderValue = slider.getValue();
                if (sliderValue == sliderValuesNumber)
                    sliderUpdate = true;
                else
                    sliderUpdate = false;
                /*
                System.out.println("slider : " + sliderValue);
                System.out.println("Millis first: "
                      + sliderData.getMilliseconds(
                   sliderValue - sliderValuesNumber)
                   .toString());
                System.out.println("Millis last : "
                      + sliderData.getMilliseconds(sliderValue)
                   .toString());
                */
                DateRange range = new DateRange(
                        sliderData.getMilliseconds(sliderValue - sliderValuesNumber).getFirstMillisecond(),
                        sliderData.getMilliseconds(sliderValue).getFirstMillisecond());
                plot.getDomainAxis().setRange(range);
            }
        }
    });
    sliderPanel.add(slider);
    // chartPanel.add(slider);
    /*
     * final Panel chartPanel2 = new Panel(); chartPanel2.add(slider);
     * content.add(chartPanel2, BorderLayout.SOUTH);
     */
    content.add(sliderPanel, BorderLayout.CENTER);
    // ===================================================

    // ===================================================
    // scrolling
    /*
     * String[] data = {"one", "two", "three", "four", "five", "six",
     * "seven", "eight", "nine", "ten"}; JList list = new JList(data);
     * 
     * // give the list some scrollbars. // the horizontal (bottom)
     * scrollbar will only appear // when the screen is too wide. The
     * vertical // scrollbar is always present, but disabled if the // list
     * is small. JScrollPane jsp = new JScrollPane(list,
     * JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
     * JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     * 
     * // add the JScrollPane (not the list) to the window.
     * getContentPane().add(jsp, BorderLayout.CENTER);
     */
    // ==================================================

    setContentPane(content);

    this.addComponentListener(new java.awt.event.ComponentAdapter() {
        public void componentResized(java.awt.event.ComponentEvent e) {
            chartPanel.setMaximumDrawWidth((int) e.getComponent().getSize().getWidth());
            chartPanel.setMaximumDrawHeight((int) e.getComponent().getSize().getHeight());
            //chartPanel.setPreferredSize(e.getComponent().getPreferredSize());
            //chartPanel.setSize(e.getComponent().getSize());
            //chartPanel.setLocation(0,0); 
        }
    });

    // start auto update plot
    autoUpdatePlot();

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.out.println("close sensor window");
            functions.windowController.closeSensorWindow();
        }

    });
}