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:tusys.view.jPanelStatistik.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    jenis_kegiatan = jComboBox1.getSelectedItem().toString();

    System.out.println(jenis_kegiatan);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    try {//ww w.  j  av  a 2 s  . co m
        tanggal_mulai = new java.sql.Date(sdf.parse(jTextFieldTanggalMulai.getText()).getTime());
        tanggal_selesai = new java.sql.Date(sdf.parse(jTextFieldTanggalSelesai.getText()).getTime());
        if (tanggal_mulai.after(tanggal_selesai)) {
            JOptionPane.showMessageDialog(null, "tanggal mulai harus sebelum tanggal selesai");
            return;
        }
    } catch (ParseException ex) {
        JOptionPane.showMessageDialog(null, "Format tanggal masukan salah");
        return;
        //Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (jenis_kegiatan.equals("Semua")) {
        try {
            stat = mainMenu.getDbc().getAllStatistic(tanggal_mulai, tanggal_selesai);
        } catch (SQLException ex) {
            Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        try {
            stat = mainMenu.getDbc().getStatistic(jenis_kegiatan, (tanggal_mulai), (tanggal_selesai));
        } catch (SQLException ex) {
            Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < stat.getRuangan().size(); i++) {
        dataset.setValue(stat.getFrekuensi().get(i), "Frekuensi", stat.getRuangan().get(i));
    }

    JFreeChart chart = ChartFactory.createBarChart("Statistik Penggunaan Ruangan", "Ruangan", "Frekuensi",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ValueAxis yAxis = chart.getCategoryPlot().getRangeAxis();
    yAxis.setRange(0.0, 100.0);
    p.setRangeAxis(yAxis);

    ChartFrame frame = new ChartFrame("Statistik", chart);
    frame.setVisible(true);
    frame.setLocation(500, 200);
    frame.setSize(565, 410);

    /*
    //masih ga keluar gambarnya
    ChartPanel cp = new ChartPanel(chart);
    jPanel1.removeAll();
    jPanel1.add(cp,BorderLayout.CENTER);
    jPanel1.revalidate();
    mainMenu.getjPanelData1().add(jPanel1);
        */

}

From source file:CorrelationLambdaTest.java

@Test

public void crossCorrelationGraphicTest() {

    CategoryTableXYDataset serie = new CategoryTableXYDataset();
    serie.setNotify(false);/*from ww  w.  j  a v  a2  s  .  c  om*/
    double step = 1.0 / discretization;
    double startPosition = step * framePosition;
    //100 ? - 100 , 50 ? - 50 , 25 ?- 25 
    Transform t = new Transform(new FastWaveletTransform(new Haar1()));
    double[] signal = testData.get1DSimpleSignal(1.5, 500, 32768, 5000);
    double[] data = crossCorrelationCoefficient(signal, window);

    //        double[] data = math.convolve(testData.get1DSignal(100, 200, frameWidth, discretization), math.lpf(70, step, 128));

    //        double[] data = math.convolve(testData.get1DSignal(100, 200, 32768, 10000), math.lpf(70, 1./10000, 32));
    //        double[] data = testData.get1DSignal(100, 200, frameWidth, discretization);
    //        double[] data = math.lpf(70, step,128);
    for (int i = 0; i < data.length; i++) {
        serie.add(startPosition, data[i], "");
        startPosition += step;
    }
    JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "wave", serie);
    chart.removeLegend();
    chart.setAntiAlias(false);

    XYPlot plot = chart.getXYPlot();
    //plot.setRangeGridlinePaint(Color.BLACK);
    org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis();
    org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis();
    double start = framePosition * 1.0 / discretization;
    double max = start + frameWidth * 1.0 / discretization;
    xAxis.setRange(start, max);
    ChartPanel chartPanel = new ChartPanel(chart);

    JPanel p = new JPanel(new BorderLayout());

    p.removeAll();
    p.add(chartPanel);
    p.validate();
    //1. Create the frame.
    JFrame frame = new JFrame("FrameDemo");

    //2. Optional: What happens when the frame closes?
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //3. Create components and put them in the frame.
    //...create emptyLabel...
    frame.getContentPane().add(new Label("olol"), BorderLayout.CENTER);
    frame.getContentPane().add(p, BorderLayout.CENTER);

    //4. Size the frame.
    frame.pack();

    //5. Show it.
    frame.setVisible(true);
}

From source file:serverrobot.DynamicGraph.java

public JFreeChart createChart(XYDataset dataset, String pos, double minRange, double maxRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(pos, "Time (ms)", "Displacement", dataset, true,
            true, false);//from www  .j av a2 s.c  o m
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(232, 232, 232));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.RED);

    ValueAxis axis = plot.getDomainAxis();
    //axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(minRange, maxRange);

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:mil.tatrc.physiology.biogears.verification.ScenarioPlotTool.java

public void createGraph(String toDir, Paint color, String title, String XAxisLabel, String YAxisLabel,
        XYSeries... xyData) {/*  w w w  . j a  va2s. co  m*/
    new File(toDir).mkdir();

    Log.info("Creating Graph " + toDir + title);
    double resMin0 = 1.e6;
    double resMax0 = -1.e6;
    double resMin1 = 1.e6;
    double resMax1 = -1.e6;

    XYSeriesCollection dataSet = new XYSeriesCollection();
    for (XYSeries data : xyData)
        dataSet.addSeries(data);

    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

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

    if (title.contains("Residual")) {
        // Make plot symmetric about x axis
        resMax0 = xyData[0].getMaxY();
        resMin0 = xyData[0].getMinY();
        if (Math.abs(xyData[0].getMinY()) > Math.abs(xyData[0].getMaxY()))
            resMax0 = Math.abs(resMin0);
        if (Math.abs(xyData[0].getMaxY()) > Math.abs(xyData[0].getMinY()))
            resMin0 = -1.0 * Math.abs(resMax0);
        if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
            resMin0 = -0.00001;
            resMax0 = 0.00001;
        }
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
    } else if (title.contains("Error")) {
        // Make plot symmetric about x axis
        resMax0 = xyData[0].getMaxY();
        resMin0 = xyData[0].getMinY();
        if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
            resMin0 = -0.00001;
            resMax0 = 0.00001;
        }
        if (resMin0 >= 0.0)
            resMin0 = -0.01;
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly

        /*
         yAxis.setTickLabelPaint(new Color(1,0,0));
         yAxis.setTickMarkPaint(new Color(1,0,0));
         yAxis.setAxisLinePaint(new Color(1,0,0));
         yAxis.setLabelPaint(new Color(1,0,0));
                
         ValueAxis xAxis = plot.getDomainAxis();
         xAxis.setTickLabelPaint(new Color(1,0,0));
         xAxis.setTickMarkPaint(new Color(1,0,0));
         yAxis.setAxisLinePaint(new Color(1,0,0));
         yAxis.setLabelPaint(new Color(1,0,0));
         */
    } else {
        if (xyData.length > 1) {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            resMax1 = xyData[1].getMaxY();
            resMin1 = xyData[1].getMinY();
            if (resMin1 < resMin0)
                resMin0 = resMin1;
            if (resMax1 > resMax0)
                resMax0 = resMax1;
            if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
                resMin0 = -0.00001;
                resMax0 = 0.00001;
            }
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
            }
        } else {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            if ((resMin0 == 0.0) && (resMax0 == 0.0)) {
                resMin0 = -0.00001;
                resMax0 = 0.00001;
            }
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly
            }
        }
    }

    formatXYPlot(chart, color);
    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(lineWidth);
    r.setSeriesStroke(0, wideLine);
    r.setSeriesStroke(1, wideLine);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    if (xyData.length > 1) {
        renderer.setSeriesStroke(//makes a dashed line
                0, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K)
                new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                        new float[] { 15.0f, 30.0f }, 0.0f));
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setUseFillPaint(true);
    }
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesFillPaint(0, expectedLineColor);
    renderer.setSeriesFillPaint(1, computedLineColor);
    renderer.setSeriesPaint(0, expectedLineColor);
    renderer.setSeriesPaint(1, computedLineColor);

    try {
        if (toDir == null || toDir.isEmpty())
            toDir = ".";
        File JPGFile = new File(toDir + "/" + StringUtils.removeParens(title) + ".jpg");
        ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesChart.java

@Override
protected JFreeChart createGraph() {
    TimeTableXYDataset dataset = createDataset();
    ValueAxis xAxis = new DateAxis();
    xAxis.setLowerMargin(0.0);//w w w  .j a  va  2  s.c  om
    xAxis.setUpperMargin(0.0);
    Calendar lowerBound = getLowerGraphBound();
    xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis());

    NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            String seriesKey = dataset.getSeriesKey(series).toString();
            StringBuilder sb = new StringBuilder();

            if (seriesKey.equals(GRAPH_OTHERS)) {
                long timeInMillis = dataset.getX(series, item).longValue();
                Date time = new Date(timeInMillis);

                TimePeriod period = null;
                if (intervalSize == Calendar.DATE) {
                    period = new Day(time);
                } else if (intervalSize == Calendar.HOUR_OF_DAY) {
                    period = new Hour(time);
                } else if (intervalSize == Calendar.MONTH) {
                    period = new Month(time);
                }
                List<FailureCauseTimeInterval> excludedDataList = excludedDataForPeriod.get(period);
                if (excludedDataList != null) {
                    Collections.sort(excludedDataList, new Comparator<FailureCauseTimeInterval>() {

                        @Override
                        public int compare(FailureCauseTimeInterval o1, FailureCauseTimeInterval o2) {
                            return o2.getNumber() - o1.getNumber();
                        }
                    });
                    for (FailureCauseTimeInterval excludedData : excludedDataList) {
                        sb.append(excludedData).append(" \n");
                    }
                }
            } else {
                int number = dataset.getY(series, item).intValue();
                sb.append(seriesKey).append(": ").append(number);
            }
            return sb.toString();
        }
    });

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.setRangeAxis(yAxis);

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

    return chart;
}

From source file:org.squale.squaleweb.util.graph.RepartitionMaker.java

/**
 * @return le diagramme JFreeChart//from  ww  w. j a v a2 s  .  c  om
 */
public JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createBarChart3D(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                false, true, true);
        CategoryPlot plot = retChart.getCategoryPlot();
        CategoryAxis xAxis = plot.getDomainAxis();
        xAxis.setAxisLineVisible(true);
        xAxis.setVisible(true);
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // On rajoute 5% pour avoir une meilleure lisibilit
        final double YAxisCoeff = 1.05;
        yAxis.setRange(PracticeResultBO.REFUSED_MIN, Math.max(mMaxValue * YAxisCoeff, 1));

        // Positionne les couleurs et les liens
        mRenderer = (CategoryItemRenderer) plot.getRenderer();
        RepartitionUrlGenerator generator = new RepartitionUrlGenerator(mProjectId, mCurrentAuditId,
                mPreviousAuditId, mPracticeId, mFactorParentId, NB_SERIES_FOR_FLOAT_GRAPH);
        mRenderer.setItemURLGenerator(generator);
        BarRenderer barRenderer = (BarRenderer) mRenderer;
        barRenderer.setBaseSeriesVisible(true);
        RepartitionToolTipGenerator toolTipGenerator = new RepartitionToolTipGenerator();
        barRenderer.setToolTipGenerator(toolTipGenerator);
        manageColor(NB_SERIES_FOR_FLOAT_GRAPH);
        retChart.setBackgroundPaint(Color.WHITE);
        super.setChart(retChart);
    }
    return retChart;
}

From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java

public void createGraph(String toDir, Paint color, String title, String XAxisLabel, String YAxisLabel,
        XYSeries... xyData) {/*from w ww. jav  a  2  s  . c o  m*/
    new File(toDir).mkdir();

    Log.info("Creating Graph " + toDir + "/" + title);
    double resMin0 = 1.e6;
    double resMax0 = -1.e6;
    double resMin1 = 1.e6;
    double resMax1 = -1.e6;

    XYSeriesCollection dataSet = new XYSeriesCollection();
    for (XYSeries data : xyData) {
        if (data != null && !data.isEmpty())
            dataSet.addSeries(data);
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    /* I have residual and error plots turned off, there are some plots that contain these names in their title, and I don't want this code running, need a better way to see if we are doing a special plot rather than title contents
        if(title.contains("Residual"))
        {
          // Make plot symmetric about x axis
          resMax0 = xyData[0].getMaxY();
          resMin0 = xyData[0].getMinY();
          if (Math.abs(xyData[0].getMinY()) > Math.abs(xyData[0].getMaxY()))  resMax0 = Math.abs(resMin0);
          if (Math.abs(xyData[0].getMaxY()) > Math.abs(xyData[0].getMinY()))  resMin0 = -1.0*Math.abs(resMax0);
          if((resMin0==0.0) && (resMax0==0.0))
          {
            resMin0 = -0.00001;
            resMax0 =  0.00001;
          }       
          ValueAxis yAxis = plot.getRangeAxis();
          yAxis.setRange(resMin0 + 0.05*resMin0, resMax0 + 0.05*resMax0);//5% buffer so we can see top and bottom clearly
        }
        else if(title.contains("Error"))
        {
          // Make plot symmetric about x axis
          resMax0 = xyData[0].getMaxY();
          resMin0 = xyData[0].getMinY();
          if((resMin0==0.0) && (resMax0==0.0))
          {
            resMin0 = -0.00001;
            resMax0 =  0.00001;
          }
          if(resMin0>=0.0) resMin0 = -0.01;
          ValueAxis yAxis = plot.getRangeAxis();
          yAxis.setRange(resMin0 + 0.05*resMin0, resMax0 + 0.05*resMax0);//5% buffer so we can see top and bottom clearly
            
          /*
           yAxis.setTickLabelPaint(new Color(1,0,0));
           yAxis.setTickMarkPaint(new Color(1,0,0));
           yAxis.setAxisLinePaint(new Color(1,0,0));
           yAxis.setLabelPaint(new Color(1,0,0));
            
           ValueAxis xAxis = plot.getDomainAxis();
           xAxis.setTickLabelPaint(new Color(1,0,0));
           xAxis.setTickMarkPaint(new Color(1,0,0));
           yAxis.setAxisLinePaint(new Color(1,0,0));
           yAxis.setLabelPaint(new Color(1,0,0));
           *
        }
        else
    */
    {
        if (title.indexOf("Hemoglobin-GlomerularFilterability") > -1)
            System.out.println("stop");
        if (xyData.length > 1) {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            resMax1 = xyData[1].getMaxY();
            resMin1 = xyData[1].getMinY();
            if (resMin1 < resMin0)
                resMin0 = resMin1;
            if (resMax1 > resMax0)
                resMax0 = resMax1;
            if (DoubleUtils.isZero(resMin0))
                resMin0 = -0.001;
            if (DoubleUtils.isZero(resMax0))
                resMax0 = 0.001;
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.15 * Math.abs(resMax0));//5% buffer so we can see top and bottom clearly
            }
            String NaNCheck = "";
            if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
                NaNCheck += "Expected is NaN ";
            if (Double.isNaN(resMax1) || Double.isNaN(resMin1))
                NaNCheck += "Computed is NaN ";
            if (!NaNCheck.isEmpty())
                plot.getDomainAxis().setLabel(NaNCheck);
        } else {
            // Make plot symmetric about x axis
            resMax0 = xyData[0].getMaxY();
            resMin0 = xyData[0].getMinY();
            if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
                plot.getDomainAxis().setLabel("Computed is NaN");
            if (DoubleUtils.isZero(resMin0))
                resMin0 = -0.001;
            if (DoubleUtils.isZero(resMax0))
                resMax0 = 0.001;
            if (resMin0 >= 0.0)
                resMin0 = -0.01;
            if (YAxisLabel.indexOf("PlasmaConcentration") > -1)
                plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")"));
            else {
                ValueAxis yAxis = plot.getRangeAxis();
                yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.15 * Math.abs(resMax0));//5% buffer so we can see top and bottom clearly
            }
        }
    }

    formatXYPlot(chart, color);
    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(lineWidth);
    r.setSeriesStroke(0, wideLine);
    r.setSeriesStroke(1, wideLine);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    if (xyData.length > 1) {
        renderer.setSeriesStroke(//makes a dashed line
                0, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K)
                new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                        new float[] { 15.0f, 30.0f }, 0.0f));
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setUseFillPaint(true);
    }
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesFillPaint(0, expectedLineColor);
    renderer.setSeriesFillPaint(1, computedLineColor);
    renderer.setSeriesPaint(0, expectedLineColor);
    renderer.setSeriesPaint(1, computedLineColor);

    try {
        if (toDir == null || toDir.isEmpty())
            toDir = ".";
        File JPGFile = new File(toDir + "/" + MakeFileName(title) + ".jpg");
        ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:support.TradingVolumeGui.java

private void startGui() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot chartFrame = createChartFrame(dataset);
    ValueAxis yAxis = chartFrame.getRangeAxis();

    long[] topY = { INITIAL_TOP_Y };
    EntryUpdatedListener<String, Long> entryUpdatedListener = event -> {
        EventQueue.invokeLater(() -> {
            dataset.addValue(event.getValue(), event.getKey(), "");
            topY[0] = max(topY[0], INITIAL_TOP_Y * (1 + event.getValue() / INITIAL_TOP_Y));
            yAxis.setRange(0, topY[0]);
        });//  www .j  a  va 2s . co  m
    };
    entryListenerId = hzMap.addEntryListener(entryUpdatedListener, true);
}

From source file:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java

/**
 * sets up all charts for later usage/*from w  w w. j  ava2 s. c om*/
 */
public void insertAllCharts() {
    for (int i = 0; i < MAXCHARTS; i++) {
        tsc[i] = new TimeSeriesCollection(new TimeSeries("unused", Millisecond.class));
        charts[i] = ChartFactory.createTimeSeriesChart("unused", null, "bitrate kbit/sec", tsc[i], false, true,
                false);

        XYPlot plot = charts[i].getXYPlot();
        ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        axis.setFixedAutoRange(DISPLAYEDTIME);
        axis = plot.getRangeAxis();
        axis.setRange(0.0, 128);
        ChartPanel chartPanel = new ChartPanel(charts[i]);

        // do the layout stuff
        GridBagConstraints c = new GridBagConstraints();
        c.weighty = 3;
        c.weightx = 10.0;
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(0, 0, 0, 0);
        c.gridx = 1;
        c.gridy = i;
        c.gridwidth = 1;
        c.gridheight = 1;
        gridBagLayout.setConstraints(chartPanel, c);

        // paste it
        content.add(chartPanel);
        chartPanel.setPreferredSize(new java.awt.Dimension(1000, 270));
    }
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.TaxaSimilarityMain.java

public void createPlot(String plotTitle, File outdir) throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset();

    PrintStream boxchart_dataStream = new PrintStream(new File(outdir, plotTitle + ".boxchart.txt"));

    boxchart_dataStream.println(/*from w w w . j a  va 2 s  .  c  o m*/
            "#\tkmer" + "\trank" + "\t" + "max" + "\t" + "avg" + "\t" + "min" + "\t" + "Q1" + "\t" + "median"
                    + "\t" + "Q3" + "\t" + "98Pct" + "\t" + "2Pct" + "\t" + "comparisons" + "\t" + "sum");
    for (int i = 0; i < ranks.size(); i++) {
        long[] countArray = sabCoutMap.get(ranks.get(i));
        if (countArray == null)
            continue;

        double sum = 0.0;
        int max = 0;
        int min = 100;
        double mean = 0;
        int Q1 = -1;
        int median = -1;
        int Q3 = -1;
        int pct_98 = -1;
        int pct_2 = -1;
        long comparisons = 0;
        int minOutlier = 0; // we don't care about the outliers
        int maxOutlier = 0; //

        XYSeries series = new XYSeries(ranks.get(i));

        for (int c = 0; c < countArray.length; c++) {
            if (countArray[c] == 0)
                continue;
            comparisons += countArray[c];
            sum += countArray[c] * c;
            if (c < min) {
                min = c;
            }
            if (c > max) {
                max = c;
            }
        }

        // create series
        double cum = 0;
        for (int c = 0; c < countArray.length; c++) {
            if (countArray[c] == 0)
                continue;
            cum += countArray[c];
            int pct = (int) Math.floor(100 * cum / comparisons);
            series.add(c, pct);

            if (pct_2 == -1 && pct >= 5) {
                pct_2 = c;
            }
            if (Q3 == -1 && pct >= 25) {
                Q3 = c;
            }
            if (median == -1 && pct >= 50) {
                median = c;
            }
            if (Q1 == -1 && pct >= 75) {
                Q1 = c;
            }
            if (pct_98 == -1 && pct >= 98) {
                pct_98 = c;
            }
        }
        if (!series.isEmpty()) {
            dataset.addSeries(series);

            BoxAndWhiskerItem item = new BoxAndWhiskerItem(sum / comparisons, median, Q1, Q3, pct_2, pct_98,
                    minOutlier, maxOutlier, new ArrayList());
            scatterDataset.add(item, ranks.get(i), "");

            boxchart_dataStream.println("#\t" + GoodWordIterator.getWordsize() + "\t" + ranks.get(i) + "\t"
                    + max + "\t" + format.format(sum / comparisons) + "\t" + min + "\t" + Q1 + "\t" + median
                    + "\t" + Q3 + "\t" + pct_98 + "\t" + pct_2 + "\t" + comparisons + "\t" + sum);
        }
    }
    boxchart_dataStream.close();
    Font lableFont = new Font("Helvetica", Font.BOLD, 28);

    JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, "Similarity%", "Percent Comparisions", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ((XYPlot) chart.getPlot()).getRenderer().setStroke(new BasicStroke(2.0f));
    chart.getLegend().setItemFont(new Font("Helvetica", Font.BOLD, 24));
    chart.getTitle().setFont(lableFont);
    ((XYPlot) chart.getPlot()).getDomainAxis().setLabelFont(lableFont);
    ((XYPlot) chart.getPlot()).getDomainAxis().setTickLabelFont(lableFont);
    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    rangeAxis.setRange(0, 100);
    rangeAxis.setTickLabelFont(lableFont);
    rangeAxis.setLabelFont(lableFont);
    ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(5));
    ChartUtilities.writeScaledChartAsPNG(new PrintStream(new File(outdir, plotTitle + ".linechart.png")), chart,
            800, 1000, 3, 3);

    BoxPlotUtils.createBoxplot(scatterDataset, new PrintStream(new File(outdir, plotTitle + ".boxchart.png")),
            plotTitle, "Rank", "Similarity%", lableFont);

}