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

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

Introduction

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

Prototype

public void setRange(double lower, double upper) 

Source Link

Document

Sets the range for the axis and sends a change event to all registered listeners.

Usage

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

public static void main(String args[]) {
    XYSeries xyseries = new XYSeries("Advisory Range");
    xyseries.add(new Integer(1200), new Integer(1));
    xyseries.add(new Integer(1500), new Integer(1));
    XYSeries xyseries1 = new XYSeries("Normal Range");
    xyseries1.add(new Integer(2000), new Integer(4));
    xyseries1.add(new Integer(2300), new Integer(4));
    XYSeries xyseries2 = new XYSeries("Recommended");
    xyseries2.add(new Integer(2100), new Integer(2));
    XYSeries xyseries3 = new XYSeries("Current");
    xyseries3.add(new Integer(2400), new Integer(3));
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(xyseries1);
    xyseriescollection.addSeries(xyseries2);
    xyseriescollection.addSeries(xyseries3);
    JFreeChart jfreechart = ChartFactory.createXYLineChart("My Chart", "Calories", "Y", xyseriescollection,
            PlotOrientation.VERTICAL, true, true, false);
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3, null);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(standardxyitemrenderer);
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setTickLabelsVisible(false);
    valueaxis.setRange(0.0D, 5D);
    ChartFrame chartframe = new ChartFrame("Test", jfreechart);
    chartframe.pack();//  w w w .j  a  v a  2 s  .  co  m
    chartframe.setVisible(true);
}

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

/**
 * Starting point for the demo.//from www. ja v a2s. c o  m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create some data...
    final XYSeries series1 = new XYSeries("Advisory Range");
    series1.add(new Integer(1200), new Integer(1));
    series1.add(new Integer(1500), new Integer(1));

    final XYSeries series2 = new XYSeries("Normal Range");
    series2.add(new Integer(2000), new Integer(4));
    series2.add(new Integer(2300), new Integer(4));

    final XYSeries series3 = new XYSeries("Recommended");
    series3.add(new Integer(2100), new Integer(2));

    final XYSeries series4 = new XYSeries("Current");
    series4.add(new Integer(2400), new Integer(3));

    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series1);
    data.addSeries(series2);
    data.addSeries(series3);
    data.addSeries(series4);

    // create a chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("My Chart", "Calories", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES, null);
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    final ValueAxis axis = plot.getRangeAxis();
    axis.setTickLabelsVisible(false);
    axis.setRange(0.0, 5.0);

    // create and display a frame...
    final ChartFrame frame = new ChartFrame("Test", chart);
    frame.pack();
    frame.setVisible(true);

}

From source file:iad_zad3.gui.Charts.java

public static JFreeChart getKmeansChart(final List<double[]> data, final List<double[]> centroids) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("", "x", "y", createDataset(data, centroids),
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesShape(1, circleSmall);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesShape(0, circleBig);
    renderer.setSeriesPaint(0, Color.BLUE);
    ValueAxis domainAxis = xyPlot.getDomainAxis();
    domainAxis.setRange(DataStats.minVal[0] * 1.2, DataStats.maxVal[0] * 1.2);
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    rangeAxis.setRange(DataStats.minVal[1] * 1.2, DataStats.maxVal[1] * 1.2);
    jfreechart.setBackgroundPaint(Color.WHITE);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Marker Demo 2", "X", "Temperature", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeTickBandPaint(new Color(240, 240, 240));
    PeriodAxis periodaxis = new PeriodAxis(null, new Hour(0, 30, 6, 2005), new Hour(23, 30, 6, 2005));
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Hour.class,
            new SimpleDateFormat("HH"));
    aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class,
            new SimpleDateFormat("dd-MMM"));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);/*  w  w w  . j a v a  2 s  . c o  m*/
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 100D);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.green);
    xyitemrenderer.setSeriesStroke(0, new BasicStroke(2.0F));
    ValueMarker valuemarker = new ValueMarker(80D);
    valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    valuemarker.setPaint(Color.red);
    valuemarker.setStroke(new BasicStroke(2.0F));
    valuemarker.setLabel("Temperature Threshold");
    valuemarker.setLabelFont(new Font("SansSerif", 0, 11));
    valuemarker.setLabelPaint(Color.red);
    valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
    xyplot.addRangeMarker(valuemarker);
    Hour hour = new Hour(18, 30, 6, 2005);
    Hour hour1 = new Hour(20, 30, 6, 2005);
    double d = hour.getFirstMillisecond();
    double d1 = hour1.getFirstMillisecond();
    IntervalMarker intervalmarker = new IntervalMarker(d, d1);
    intervalmarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    intervalmarker.setPaint(new Color(150, 150, 255));
    intervalmarker.setLabel("Automatic Cooling");
    intervalmarker.setLabelFont(new Font("SansSerif", 0, 11));
    intervalmarker.setLabelPaint(Color.blue);
    intervalmarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    intervalmarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    xyplot.addDomainMarker(intervalmarker, Layer.BACKGROUND);
    ValueMarker valuemarker1 = new ValueMarker(d, Color.blue, new BasicStroke(2.0F));
    ValueMarker valuemarker2 = new ValueMarker(d1, Color.blue, new BasicStroke(2.0F));
    xyplot.addDomainMarker(valuemarker1, Layer.BACKGROUND);
    xyplot.addDomainMarker(valuemarker2, Layer.BACKGROUND);
    return jfreechart;
}

From source file:org.gephi.statistics.plugin.ChartUtils.java

public static void scaleChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(1.0);//from  w ww  .  ja  va2 s  .  co m
    domainAxis.setUpperMargin(1.0);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (normalized) {
        domainAxis.setRange(-0.05, 1.05);
    } else {
        domainAxis.setRange(dSeries.getMinX() - 1, dSeries.getMaxX() + 1);
    }
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(-0.1 * Math.sqrt(dSeries.getMaxY()),
            dSeries.getMaxY() + 0.1 * Math.sqrt(dSeries.getMaxY()));
}

From source file:y.graphs.ChartHelperELF.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  ww  w. jav a 2 s.com

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundELF());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //            renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //        rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:y.graphs.ChartHelperSRB.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  w  ww .j  a  v a 2 s . c o  m

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundSRB());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //          renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //      rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:temp1.RealTimeChart.java

public static JFreeChart createChart(String chartContent, String title, String yaxisName) {
    thread1 = new Thread();
    timeseries1 = new TimeSeries(chartContent, Millisecond.class);
    timeseries2 = new TimeSeries(chartContent, Millisecond.class);
    timeseries3 = new TimeSeries(chartContent, Millisecond.class);
    timeseries4 = new TimeSeries(chartContent, Millisecond.class);

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1);
    TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2);
    TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3);
    TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4);

    jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false);

    final XYPlot xyplot = jfreechart.getXYPlot();
    xyplot.setOutlinePaint(Color.magenta);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.gray);
    xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);/*from  w  ww . j ava2 s . c om*/
    valueaxis.setFixedAutoRange(20000D);
    //Value
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(800D, 3300D);
    xyplot.setDataset(0, timeseriescollection);
    xyplot.setDataset(1, timeseriescollection1);
    xyplot.setDataset(2, timeseriescollection2);
    xyplot.setDataset(3, timeseriescollection3);
    XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xylineandshaperenderer0.setBaseShapesVisible(false);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer3.setBaseShapesVisible(false);
    xylineandshaperenderer0.setSeriesPaint(0, Color.RED);
    xylineandshaperenderer1.setSeriesPaint(0, Color.cyan);
    xylineandshaperenderer2.setSeriesPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(0, xylineandshaperenderer0);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F));
    return jfreechart;
}

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static JFreeChart createWindChart(WindDataset dataset) {
    ValueAxis xAxis = new DateAxis(xAxisLabel);
    ValueAxis yAxis = new NumberAxis("Direction / Force");
    yAxis.setRange(-12.0, 12.0);

    WindItemRenderer renderer = new WindItemRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }/* ww  w.  j a v  a 2 s  .c  o m*/
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    JFreeChart chart = new JFreeChart("Wind Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;
}

From source file:org.gumtree.vis.awt.PlotFactory.java

public static JFreeChart createTimeChart(ITimeSeriesSet timeSeriesSet) {
    //      TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    JFreeChart chart = ChartFactory.createTimeSeriesChart(timeSeriesSet.getTitle(), null,
            timeSeriesSet.getYTitle()//from  ww w. jav a  2s . co m
                    + (timeSeriesSet.getYUnits() != null ? " (" + timeSeriesSet.getYUnits() + ")" : ""),
            timeSeriesSet, true, true, false);
    XYPlot xyplot = chart.getXYPlot();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    //        valueaxis.setFixedAutoRange(60000D);   
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 200D);
    valueaxis.setAutoRange(true);
    XYItemRenderer renderer = xyplot.getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(false);
    }
    chartTheme.apply(chart);
    Font font = valueaxis.getLabelFont();
    valueaxis.setLabelFont(font.deriveFont(Font.PLAIN));
    return chart;
}