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

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

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis 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.matsim.contrib.analysis.christoph.ActivitiesAnalyzer.java

@Override
public void notifyIterationEnds(IterationEndsEvent event) {

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

    try {//from   ww  w .  j a  v  a2  s. c  o  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.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java

private void buildMainChart(String title, String subTitle, String xAxisLabel, String yAxisLabel,
        String fileName) {//  ww w  .j a  v  a  2 s .  c om
    final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createMatrixDataSet());

    final JFreeChart chart = ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.addSubtitle(new TextTitle(subTitle));
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE));
    chart.removeLegend();

    // Perform customizations starts here ...
    final XYPlot plot1 = chart.getXYPlot();

    plot1.setDomainGridlinesVisible(false);
    plot1.setRangeGridlinesVisible(false);
    plot1.setForegroundAlpha(0.5f);
    plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel()));
    plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel()));

    // Custumize the domain axis ( y )
    final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-1, this.array.length);

    // Custumize the range axis ( y )
    final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(-1, this.array.length);

    // Create custom renderer
    StandardXYItemRenderer ren = new CustomRenderer(false);
    ren.setSeriesItemLabelPaint(0, Color.BLACK);
    plot1.setRenderer(ren);
    this.mainChart = chart;
}

From source file:org.rdv.viz.spectrum.SpectrumAnalyzerPanel.java

/**
 * Initializes the chart./*  w  w  w .  j a v  a2  s.c o  m*/
 */
private void initChart() {
    xySeries = new SpectrumXYSeries("", false, false);

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    xySeriesCollection.addSeries(xySeries);

    chart = ChartFactory.createXYLineChart(null, "Frequency (Hz)", null, xySeriesCollection,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setAntiAlias(false);

    XYPlot xyPlot = (XYPlot) chart.getPlot();
    NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
    xAxis.setRange(0, sampleRate / 2);

    setChart(chart);
}

From source file:ch.ksfx.web.services.chart.ObservationChartGenerator.java

public void setRange(JFreeChart jFreeChart, List<Observation> observations) {
    //This has to be sorted by value!!
    List<Observation> sortedObservations = new ArrayList<Observation>(observations);
    Collections.sort(sortedObservations, new ObservationDoubleValueComparator());

    XYPlot xyp = jFreeChart.getXYPlot();

    //xyp.addAnnotation(new XYTextAnnotation("Fummel", dataset.getX(0,10).doubleValue(), dataset.getY(0, 10).doubleValue()));

    NumberAxis axis = (NumberAxis) xyp.getRangeAxis();

    Double width = Double.parseDouble(sortedObservations.get(sortedObservations.size() - 1).getScalarValue())
            - Double.parseDouble(sortedObservations.get(0).getScalarValue());

    axis.setRange(Double.parseDouble(sortedObservations.get(0).getScalarValue()) - width / 4,
            Double.parseDouble(sortedObservations.get(sortedObservations.size() - 1).getScalarValue())
                    + width / 4);//from w w  w .  j a v a2 s. c om

    DateAxis daxis = new DateAxis("Time Axis");

    daxis.setVerticalTickLabels(true);

    daxis.setTickMarkPosition(DateTickMarkPosition.START);
    daxis.setAutoRange(true);
    daxis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"));
    xyp.setDomainAxis(daxis);

}

From source file:org.rdv.viz.spectrum.SpectrumAnalyzerPanel.java

/**
 * Sets the sample rate. The sample rate must be positive.
 * /*from   ww w . j a va  2 s. c o  m*/
 * @param sampleRate  the new sample rate
 */
public void setSampleRate(double sampleRate) {
    if (sampleRate <= 0) {
        throw new IllegalArgumentException("Sample rate must be positive.");
    }

    if (this.sampleRate == sampleRate) {
        return;
    }

    double oldSampleRate = this.sampleRate;
    this.sampleRate = sampleRate;

    firePropertyChange(SAMPLE_RATE_PROPERTY, oldSampleRate, sampleRate);

    // set the x-axis range
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
    xAxis.setRange(0, sampleRate / 2);

    plotSpectrum();
}

From source file:grafix.graficos.eixos.Eixo.java

public void configurarEscalaVertical(XYPlot plot) {
    NumberAxis nAxis = (NumberAxis) plot.getRangeAxis();
    if (this.isAutoEscala()) {
        if (this.isIncluiZero()) {
            nAxis.setAutoRange(true);//  w ww  . j  a  v a  2s .c  o m
            nAxis.setAutoRangeIncludesZero(true);
        } else {
            nAxis.setAutoRange(true);
            nAxis.setAutoRangeIncludesZero(false);
        }
    } else {
        if (this.isIncluiZero()) {
            nAxis.setRange(Math.min(getEscalaMin(), 0), Math.max(0, getEscalaMax()));
        } else {
            nAxis.setRange(getEscalaMin(), getEscalaMax());
        }
    }
}

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java

private void buildLegendChart(int nbValues) {
    this.legendValues = new int[nbValues + 1];
    this.legendValues[0] = 0;
    int offset = 255 / nbValues;
    int step = offset;

    if (this.scaleMode == Chart.Scale.LOGARITHMIC) {
        double logStep = (Math.log(this.maxValue) / Math.log(2)) / nbValues;
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (int) Math.pow(2, logStep * i);
        }//from  w  w w  .j a v  a 2  s  .  c o  m
    } else { // Linear scale mode
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (step * this.maxValue) / 255;
            step += offset;
        }
    }

    final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createLegendDataSet());

    final JFreeChart chart = ChartFactory.createBubbleChart("", "", "", dataset, PlotOrientation.VERTICAL, true,
            true, false);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE));
    chart.removeLegend();

    // Perform customizations starts here ...
    final XYPlot plot1 = chart.getXYPlot();

    plot1.setDomainGridlinesVisible(false);
    plot1.setRangeGridlinesVisible(false);
    plot1.setForegroundAlpha(0.5f);
    plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel()));
    plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel()));

    // Custumize the domain axis ( x )
    final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-1, 1);
    domainAxis.setVisible(false);

    // Custumize the range axis ( y )
    final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
    rangeAxis.setTickUnit(new CustomTickUnit(rangeAxis.getTickUnit().getSize()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(-1, this.legendValues.length);
    rangeAxis.setTickLabelsVisible(true);
    rangeAxis.setTickMarkInsideLength(4);

    // Create custom renderer
    StandardXYItemRenderer ren = new CustomRenderer(true);
    ren.setSeriesItemLabelPaint(0, Color.BLUE);
    plot1.setRenderer(ren);
    plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);

    this.legendChart = chart;
}

From source file:view.Dashboard.java

public void updateChart() {
    if (cc.getConnectionStatus()) {
        try {/*  w ww. ja  va2  s .c  o  m*/
            double data = cc.readData();
            if (counter == 1000) {
                voltageSeries.remove(0);
                setPointSeries.remove(0);
            } else if (counter < 1000) {
                counter++;
            }
            voltageSeries.add(currentTime * 50, data);
            setPointSeries.add(currentTime * 50, setPoint);
            xyPlot = (XYPlot) voltageLineChart.getPlot();
            xyPlot.setDomainCrosshairVisible(true);
            xyPlot.setRangeCrosshairVisible(true);
            NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
            domain.setRange(currentTime * 50 - tickpoint * 10, currentTime * 50);
            System.out.println(voltageSeries.getItemCount());
            domain.setTickUnit(new NumberTickUnit(tickpoint));
            currentTime++;
            NumberAxis range = (NumberAxis) xyPlot.getRangeAxis();
            switch (setRangeY) {
            case 1:
                range.setRange(0, 5);
                range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                break;
            case 2:
                range.setRange(0, 10);
                range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                break;
            case 3:
                range.setRange(0, 15);
                range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                break;
            default:
                range.setAutoRange(true);
                range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                break;
            }
        } catch (SerialPortTimeoutException ex) {
            timer.stop();
            cc.setConnectionStatus(false);
            cc.setReadStatus(false);
        }
    } else {
        timer.stop();
    }
}

From source file:edu.fullerton.ldvservlet.SrcList.java

private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage,
        ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException {
    PageItemList ret = new PageItemList();
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)"));
    plot.setGap(10.0);/*from   ww w  .j  av a  2 s .  c  o  m*/

    String baseName = "";
    StringBuilder errors = new StringBuilder();
    int plotNum = 0;
    Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN };
    boolean gotData = false;
    TimeInterval timeRange = null;
    for (ChanSourceData csd : csdList) {
        TimeInterval ti = csd.getTimeRange();
        if (ti != null) {
            if (timeRange == null) {
                timeRange = ti;
            } else if (timeRange.overlaps(ti)) {
                timeRange = timeRange.mergeIntervals(ti);
            } else if (ti.getStartGps() < timeRange.getStartGps()) {
                timeRange.setStartGps(ti.getStartGps());
            } else if (ti.getStopGps() > timeRange.getStopGps()) {
                timeRange.setStopGps(ti.getStopGps());
            }
        }
    }
    if (timeRange != null) {
        for (ChanSourceData csd : csdList) {
            baseName = csd.getChanInfo().getBaseName();
            TimeSeriesCollection mtds = new TimeSeriesCollection();
            String server = csd.getChanInfo().getServer().replace(".caltech.edu", "");
            String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server);
            TimeSeries ts;
            double[][] data = csd.getGraphData();
            if (data == null) {
                data = new double[2][2];
                data[0][0] = timeRange.getStartGps();
                data[1][0] = timeRange.getStopGps();
                data[0][1] = data[1][1] = 0;
                errors.append("Error getting data for: ").append(legend).append("<br>");
            } else {
                gotData = true;
            }
            for (double[] d : data) {
                d[1] = d[1] <= 1 ? 1 : d[1];
            }
            ts = getTimeSeries(data, legend);

            mtds.addSeries(ts);
            XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);

            BasicStroke str = new BasicStroke(2);
            int colorIdx = plotNum % colors.length;
            Color color = colors[colorIdx];
            NumberAxis yAxis = new NumberAxis("% Avail");
            yAxis.setRange(0, 100);
            renderer.setBaseFillPaint(color);
            renderer.setSeriesFillPaint(0, Color.WHITE);
            renderer.setBaseStroke(str);
            renderer.setUseFillPaint(true);
            XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer);
            plot.add(subplot);

            plotNum++;
        }

        ChartPanel cpnl;
        JFreeChart chart;
        String gtitle = String.format("Available data for %1$s ", baseName);
        String subTitleTxt = String.format("From %1$s to %2$s",
                TimeAndDate.gpsAsUtcString(timeRange.getStartGps()),
                TimeAndDate.gpsAsUtcString(timeRange.getStopGps()));

        plot.setOrientation(PlotOrientation.VERTICAL);

        chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

        chart.addSubtitle(new TextTitle(subTitleTxt));
        cpnl = new ChartPanel(chart, false, false, false, false, false);

        PluginSupport psupport = new PluginSupport();
        psupport.setup(db, vpage, vuser);
        int imgId;
        PageItemImage img = null;
        try {
            psupport.setSize(800, 600);
            imgId = psupport.saveImageAsPNG(cpnl);
            String url = String.format("%1$s/view?act=getImg&amp;imgId=%2$d", contextPath, imgId);

            img = new PageItemImage(url, "availability", baseName);

        } catch (SQLException | IOException | NoSuchAlgorithmException ex) {
            String ermsg = String.format("Error creating or saving image: %1$s - $2$s",
                    ex.getClass().getSimpleName(), ex.getLocalizedMessage());
            errors.append(ermsg);

        }
        if (errors.length() > 0) {
            ret.add(errors.toString());
        }
        if (img != null) {
            ret.add(img);
        }
    } else {
        ret.add("No data to plot.");
    }
    return ret;
}

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

private void configureAxis(XYPlot plot, int start, int end) {
    int nb = graphs_.size();
    List<String> names = new ArrayList<>();
    for (int i = start; i <= end; i++) {
        names.add(periods.get(i).toString());
    }/*from  ww  w .  j a  v  a 2 s.  co m*/

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelPaint(Color.GRAY);
    xAxis.setTickUnit(new MyTickUnit(names));
    xAxis.setRange(-0.5, nb - 0.5);
    xAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(xAxis);
    plot.setDomainGridlinesVisible(false);
    NumberAxis yaxis = new NumberAxis();
    rescaleAxis(yaxis);
    yaxis.configure();
    plot.setRangeAxis(yaxis);

    for (int i = 0; i < nb; i++) {
        ValueMarker marker = new ValueMarker(i + 0.5);
        marker.setStroke(MARKER_STROKE);
        marker.setPaint(MARKER_PAINT);
        marker.setAlpha(MARKER_ALPHA);
        plot.addDomainMarker(marker);
    }
}