Example usage for org.jfree.data.time TimeSeries TimeSeries

List of usage examples for org.jfree.data.time TimeSeries TimeSeries

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries TimeSeries.

Prototype

public TimeSeries(Comparable name, Class timePeriodClass) 

Source Link

Document

Creates a new (empty) time series with the specified name and class of RegularTimePeriod .

Usage

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Create the charts//from w  w w . j a  v  a 2  s  .  c  om
 *
 * @throws RemoteException On badness
 * @throws VisADException On badness
 */
public void loadDatax() throws VisADException, RemoteException {

    createChart();
    times = null;
    List unitList = new ArrayList();
    List dataChoiceWrappers = getDataChoiceWrappers();
    datas.clear();
    ranges.clear();
    try {
        plot.setIgnoreDataSetChanges(true);
        plot.clearRangeAxes();
        plot.setRangeAxis(0, new NumberAxis(""), false);
        for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) {
            TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }

        //            plot.clearDatasets();
        //            dataset.setDomainIsPointsInTime(true);
        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        AxisLocation lastSide = AxisLocation.BOTTOM_OR_RIGHT;
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);
            DataChoice dataChoice = wrapper.getDataChoice();
            FlatField data = getFlatField((FieldImpl) dataChoice.getData(null, props));
            Set domainSet = data.getDomainSet();
            double[][] domain = domainSet.getDoubles(false);
            double[][] samples = data.getValues(false);
            double[] var = samples[0];

            Unit unit = ucar.visad.Util.getDefaultRangeUnits(data)[0];
            Unit displayUnit = null;
            if (unit != null) {
                displayUnit = getDisplayControl().getDisplayConventions().getDisplayUnit(dataChoice.getName(),
                        null);
                if ((displayUnit != null) && !displayUnit.equals(unit)) {
                    var = displayUnit.toThis(var, unit);
                    unit = displayUnit;

                }
            }

            unitList.add(unit);
            double[] timeValues = getTimeValues(samples, (FlatField) data);
            double[][] result = filterData(var, timeValues);
            var = result[0];
            timeValues = result[1];
            TimeSeries series = new TimeSeries(dataChoice.getName() + ((unit == null) ? "" : " [" + unit + "]"),
                    FixedMillisecond.class);

            //TODO: Find the lat/lon/alt index in the domain
            times = timeValues;
            lats = domain[0];
            lons = domain[1];
            alts = domain[2];
            datas.add(var);
            long t1 = System.currentTimeMillis();
            double min = 0;
            double max = 0;
            for (int i = 0; i < var.length; i++) {
                Date dttm = new Date((long) (timeValues[i]));
                //                    series.addOrUpdate(new FixedMillisecond(dttm), var[i]);
                series.add(new FixedMillisecond(dttm), var[i]);
                if ((i == 0) || (var[i] < min)) {
                    min = var[i];
                }
                if ((i == 0) || (var[i] > max)) {
                    max = var[i];
                }
            }
            ranges.add(new ucar.unidata.util.Range(min, max));

            long t2 = System.currentTimeMillis();
            //                System.err.println ("\t time to add:" + (t2-t1));

            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.setDomainIsPointsInTime(true);
            dataset.addSeries(series);
            NumberAxis rangeAxis = new NumberAxis(wrapper.getLabel(unit));
            plot.setRangeAxis(paramIdx, rangeAxis, false);
            plot.setDataset(paramIdx, dataset);

            XYItemRenderer renderer = doMakeRenderer();
            plot.setRenderer(paramIdx, renderer);
            plot.mapDatasetToRangeAxis(paramIdx, paramIdx);
            Color c = wrapper.getColor(paramIdx);
            rangeAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);
            renderer.setSeriesStroke(0, wrapper.getLineState().getStroke());

            AxisLocation side;
            if (wrapper.getSide() == wrapper.SIDE_UNDEFINED) {
                if (lastSide == AxisLocation.TOP_OR_LEFT) {
                    side = AxisLocation.BOTTOM_OR_RIGHT;
                } else {
                    side = AxisLocation.TOP_OR_LEFT;
                }
            } else if (wrapper.getSide() == wrapper.SIDE_LEFT) {
                side = AxisLocation.TOP_OR_LEFT;
            } else {
                side = AxisLocation.BOTTOM_OR_RIGHT;
            }
            lastSide = side;
            plot.setRangeAxisLocation(paramIdx, side);
        }
    } catch (Exception exc) {
        LogUtil.logException("Error creating data set", exc);
        return;
    }

    if (dataChoiceWrappers.size() == 0) {
        NumberAxis axis = new NumberAxis("");
        plot.setRangeAxis(0, axis, false);
        ValueAxis timeAxis = doMakeDateAxis();
        plot.setDomainAxis(0, timeAxis, false);
    }

    plot.setIgnoreDataSetChanges(false);

    try {
        setLocationPositions();
    } catch (Exception exc) {
        LogUtil.logException("Error creating wayPoints", exc);
    }
}

From source file:org.efs.openreports.engine.ChartReportEngine.java

private static XYDataset createTimeDataset(ChartValue[] values) {
    TimeSeries series = null;/*from w ww  .  ja  v  a  2 s  .co  m*/
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();

    for (int i = 0; i < values.length; i++) {
        TimeChartValue value = (TimeChartValue) values[i];

        if (series == null || !series.getKey().equals(value.getSeries())) {
            if (series != null) {
                seriesCollection.addSeries(series);
            }

            series = new TimeSeries(value.getSeries(), Second.class);
        }

        series.add(new Second(value.getTime()), value.getValue());
    }

    seriesCollection.addSeries(series);

    return seriesCollection;
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Two classes with different period classes are NOT the same.
 *//*from  w  ww.  j a  v  a 2  s  . c  o m*/
@Test
public void testEquals3() {
    TimeSeries s1 = new TimeSeries("Series", Day.class);
    TimeSeries s2 = new TimeSeries("Series", Month.class);
    assertFalse(s1.equals(s2));
}

From source file:org.openmrs.web.servlet.ShowGraphServlet.java

/**
 * The main method for this class. It will create a JFreeChart object to be written to the
 * response./*from  w w  w .  ja v a 2s .  c o m*/
 *
 * @param request the current request will all the parameters needed
 * @return JFreeChart object to be rendered
 * @should set value axis label to given units
 * @should set value axis label to concept numeric units if given units is null
 */
protected JFreeChart getChart(HttpServletRequest request) {
    // All available GET parameters
    String patientId = request.getParameter("patientId"); // required
    String conceptId1 = request.getParameter("conceptId"); // required
    String conceptId2 = request.getParameter("conceptId2");
    String chartTitle = request.getParameter("chartTitle");
    String units = request.getParameter("units");

    String minRangeString = request.getParameter("minRange");
    String maxRangeString = request.getParameter("maxRange");

    String hideDate = request.getParameter("hideDate");

    Patient patient = Context.getPatientService().getPatient(Integer.parseInt(patientId));

    // Set date range to passed values, otherwise set a default date range to the last 12 months
    Calendar cal = Calendar.getInstance();
    Date fromDate = getFromDate(request.getParameter("fromDate"));
    Date toDate = getToDate(request.getParameter("toDate"));

    // Swap if fromDate is after toDate
    if (fromDate.getTime() > toDate.getTime()) {
        Long temp = fromDate.getTime();
        fromDate.setTime(toDate.getTime());
        toDate.setTime(temp);
    }

    // Graph parameters
    Double minRange = null;
    Double maxRange = null;
    Double normalLow = null;
    Double normalHigh = null;
    Double criticalLow = null;
    Double criticalHigh = null;
    String timeAxisTitle = null;
    String rangeAxisTitle = null;
    boolean userSpecifiedMaxRange = false;
    boolean userSpecifiedMinRange = false;

    // Fetching obs
    List<Obs> observations1 = new ArrayList<Obs>();
    List<Obs> observations2 = new ArrayList<Obs>();
    Concept concept1 = null, concept2 = null;
    if (conceptId1 != null) {
        concept1 = Context.getConceptService().getConcept(Integer.parseInt(conceptId1));
    }
    if (conceptId2 != null) {
        concept2 = Context.getConceptService().getConcept(Integer.parseInt(conceptId2));
    }
    if (concept1 != null) {
        observations1 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept1);
        chartTitle = concept1.getName().getName();
        rangeAxisTitle = ((ConceptNumeric) concept1).getUnits();
        minRange = ((ConceptNumeric) concept1).getLowAbsolute();
        maxRange = ((ConceptNumeric) concept1).getHiAbsolute();
        normalLow = ((ConceptNumeric) concept1).getLowNormal();
        normalHigh = ((ConceptNumeric) concept1).getHiNormal();
        criticalLow = ((ConceptNumeric) concept1).getLowCritical();
        criticalHigh = ((ConceptNumeric) concept1).getHiCritical();

        // Only get observations2 if both concepts share the same units; update chart title and ranges
        if (concept2 != null) {
            String concept2Units = ((ConceptNumeric) concept2).getUnits();
            if (concept2Units != null && concept2Units.equals(rangeAxisTitle)) {
                observations2 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept2);
                chartTitle += " + " + concept2.getName().getName();
                if (((ConceptNumeric) concept2).getHiAbsolute() != null
                        && ((ConceptNumeric) concept2).getHiAbsolute() > maxRange) {
                    maxRange = ((ConceptNumeric) concept2).getHiAbsolute();
                }
                if (((ConceptNumeric) concept2).getLowAbsolute() != null
                        && ((ConceptNumeric) concept2).getLowAbsolute() < minRange) {
                    minRange = ((ConceptNumeric) concept2).getLowAbsolute();
                }
            } else {
                log.warn("Units for concept id: " + conceptId2 + " don't match units for concept id: "
                        + conceptId1 + ". Only displaying " + conceptId1);
                concept2 = null; // nullify concept2 so that the legend isn't shown later
            }
        }
    } else {
        chartTitle = "Concept " + conceptId1 + " not found";
        rangeAxisTitle = "Value";
    }

    // Overwrite with user-specified values, otherwise use default values
    if (units != null && units.length() > 0) {
        rangeAxisTitle = units;
    }
    if (minRangeString != null) {
        minRange = Double.parseDouble(minRangeString);
        userSpecifiedMinRange = true;
    }
    if (maxRangeString != null) {
        maxRange = Double.parseDouble(maxRangeString);
        userSpecifiedMaxRange = true;
    }
    if (chartTitle == null) {
        chartTitle = "";
    }
    if (rangeAxisTitle == null) {
        rangeAxisTitle = "";
    }
    if (minRange == null) {
        minRange = 0.0;
    }
    if (maxRange == null) {
        maxRange = 200.0;
    }

    // Create data set
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series1, series2;

    // Interval-dependent units
    Class<? extends RegularTimePeriod> timeScale = null;
    if (toDate.getTime() - fromDate.getTime() <= 86400000) {
        // Interval <= 1 day: minutely
        timeScale = Minute.class;
        timeAxisTitle = "Time";
    } else if (toDate.getTime() - fromDate.getTime() <= 259200000) {
        // Interval <= 3 days: hourly
        timeScale = Hour.class;
        timeAxisTitle = "Time";
    } else {
        timeScale = Day.class;
        timeAxisTitle = "Date";
    }
    if (concept1 == null) {
        series1 = new TimeSeries("NULL", Hour.class);
    } else {
        series1 = new TimeSeries(concept1.getName().getName(), timeScale);
    }
    if (concept2 == null) {
        series2 = new TimeSeries("NULL", Hour.class);
    } else {
        series2 = new TimeSeries(concept2.getName().getName(), timeScale);
    }

    // Add data points for concept1
    for (Obs obs : observations1) {
        if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime()
                && obs.getObsDatetime().getTime() < toDate.getTime()) {
            cal.setTime(obs.getObsDatetime());
            if (timeScale == Minute.class) {
                Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY),
                        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
                series1.addOrUpdate(min, obs.getValueNumeric());
            } else if (timeScale == Hour.class) {
                Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH),
                        cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
                series1.addOrUpdate(hour, obs.getValueNumeric());
            } else {
                Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1,
                        cal.get(Calendar.YEAR));
                series1.addOrUpdate(day, obs.getValueNumeric());
            }
        }
    }

    // Add data points for concept2
    for (Obs obs : observations2) {
        if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime()
                && obs.getObsDatetime().getTime() < toDate.getTime()) {
            cal.setTime(obs.getObsDatetime());
            if (timeScale == Minute.class) {
                Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY),
                        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
                series2.addOrUpdate(min, obs.getValueNumeric());
            } else if (timeScale == Hour.class) {
                Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH),
                        cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
                series2.addOrUpdate(hour, obs.getValueNumeric());
            } else {
                Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1,
                        cal.get(Calendar.YEAR));
                series2.addOrUpdate(day, obs.getValueNumeric());
            }
        }
    }

    // Add series to dataset
    dataset.addSeries(series1);
    if (!series2.isEmpty()) {
        dataset.addSeries(series2);
    }

    // As of JFreeChart 1.0.11 the default background color is dark grey instead of white.
    // This line restores the original white background.
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());

    JFreeChart chart = null;

    // Show legend only if more than one series
    if (concept2 == null) {
        chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, false,
                false, false);
    } else {
        chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, true,
                false, false);
    }

    // Customize title font
    Font font = new Font("Arial", Font.BOLD, 12);
    TextTitle title = chart.getTitle();
    title.setFont(font);
    chart.setTitle(title);

    // Add subtitle, unless 'hideDate' has been passed
    if (hideDate == null) {
        TextTitle subtitle = new TextTitle(fromDate.toString() + " - " + toDate.toString());
        subtitle.setFont(font);
        chart.addSubtitle(subtitle);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("No Data Available");

    // Add abnormal/critical range background color (only for single-concept graphs)
    if (concept2 == null) {
        IntervalMarker abnormalLow, abnormalHigh, critical;
        if (normalHigh != null) {
            abnormalHigh = new IntervalMarker(normalHigh, maxRange, COLOR_ABNORMAL);
            plot.addRangeMarker(abnormalHigh);
        }
        if (normalLow != null) {
            abnormalLow = new IntervalMarker(minRange, normalLow, COLOR_ABNORMAL);
            plot.addRangeMarker(abnormalLow);
        }
        if (criticalHigh != null) {
            critical = new IntervalMarker(criticalHigh, maxRange, COLOR_CRITICAL);
            plot.addRangeMarker(critical);
        }
        if (criticalLow != null) {
            critical = new IntervalMarker(minRange, criticalLow, COLOR_CRITICAL);
            plot.addRangeMarker(critical);
        }

        // there is data outside of the absolute lower limits for this concept (or of what the user specified as minrange)
        if (plot.getRangeAxis().getLowerBound() < minRange) {
            IntervalMarker error = new IntervalMarker(plot.getRangeAxis().getLowerBound(), minRange,
                    COLOR_ERROR);
            plot.addRangeMarker(error);
        }

        if (plot.getRangeAxis().getUpperBound() > maxRange) {
            IntervalMarker error = new IntervalMarker(maxRange, plot.getRangeAxis().getUpperBound(),
                    COLOR_ERROR);
            plot.addRangeMarker(error);
        }

    }

    // Visuals
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesFilled(true);
        renderer.setBaseShapesVisible(true);
    }

    // Customize the plot (range and domain axes)

    // Modify x-axis (datetime)
    DateAxis timeAxis = (DateAxis) plot.getDomainAxis();
    if (timeScale == Day.class) {
        timeAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy"));
    }

    timeAxis.setRange(fromDate, toDate);

    // Set y-axis range (values)
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (userSpecifiedMinRange) {
        minRange = (rangeAxis.getLowerBound() < minRange) ? rangeAxis.getLowerBound() : minRange;
    }

    if (userSpecifiedMaxRange) {
        // otherwise we just use default range
        maxRange = (rangeAxis.getUpperBound() > maxRange) ? rangeAxis.getUpperBound() : maxRange;
    }

    rangeAxis.setRange(minRange, maxRange);

    return chart;
}

From source file:se.six.jmeter.visualizer.statagg.StatAggVisualizer.java

private void setupTimeSeries() {
    _throughPutSeries = new TimeSeries("Throughput, hits/sec", Second.class);
    _throughPutSeries.setMaximumItemCount(_maxChartItemCount);
    _averageSeries = new TimeSeries("Average Response Time, msec", Second.class);
    _averageSeries.setMaximumItemCount(_maxChartItemCount);
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Some tests to ensure that the createCopy(RegularTimePeriod,
 * RegularTimePeriod) method is functioning correctly.
 *//*from   w  w  w . ja v  a  2 s.  c o  m*/
@Test
public void testCreateCopy1() {
    TimeSeries series = new TimeSeries("Series", Month.class);
    series.add(new Month(MonthConstants.JANUARY, 2003), 45.0);
    series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0);
    series.add(new Month(MonthConstants.JUNE, 2003), 35.0);
    series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0);
    series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0);

    try {
        // copy a range before the start of the series data...
        TimeSeries result1 = series.createCopy(new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2002));
        assertEquals(0, result1.getItemCount());

        // copy a range that includes only the first item in the series...
        TimeSeries result2 = series.createCopy(new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result2.getItemCount());

        // copy a range that begins before and ends in the middle of the
        // series...
        TimeSeries result3 = series.createCopy(new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result3.getItemCount());

        TimeSeries result4 = series.createCopy(new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result4.getItemCount());

        TimeSeries result5 = series.createCopy(new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result5.getItemCount());

        TimeSeries result6 = series.createCopy(new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result6.getItemCount());

        TimeSeries result7 = series.createCopy(new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result7.getItemCount());

        TimeSeries result8 = series.createCopy(new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result8.getItemCount());

        TimeSeries result9 = series.createCopy(new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result9.getItemCount());

        TimeSeries result10 = series.createCopy(new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(3, result10.getItemCount());

        TimeSeries result11 = series.createCopy(new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(3, result11.getItemCount());

        TimeSeries result12 = series.createCopy(new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(1, result12.getItemCount());

        TimeSeries result13 = series.createCopy(new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(1, result13.getItemCount());

        TimeSeries result14 = series.createCopy(new Month(MonthConstants.JANUARY, 2004),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(0, result14.getItemCount());
    } catch (CloneNotSupportedException e) {
        assertTrue(false);
    }
}

From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java

private JFreeChart createIndexChart() {
    // init Time-Series
    TimeSeries indexSizeSeries = new TimeSeries("Index Size", Minute.class);
    indexSizeSeries.setMaximumItemAge(24 * 60);
    this.seriesMap.put(TSERIES_INDEX_SIZE, indexSizeSeries);

    // init chart
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "#Docs",
            new TimeSeriesCollection(indexSizeSeries), true, false, false);

    XYPlot plot = chart.getXYPlot();/*www .  j  av  a2 s .c  om*/

    final TimeSeriesCollection linksDataset = new TimeSeriesCollection();

    TimeSeries totalLinksSeries = new TimeSeries("Total URI", Minute.class);
    totalLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(totalLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_TOTAL, totalLinksSeries);

    TimeSeries enqueuedLinksSeries = new TimeSeries("Enqueued URI", Minute.class);
    enqueuedLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(enqueuedLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_ENQUEUD, enqueuedLinksSeries);

    NumberAxis axis2 = new NumberAxis("#Links");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setNumberFormatOverride(new DecimalFormat("#,##0"));
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, linksDataset);
    plot.setRenderer(1, new StandardXYItemRenderer());
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis axis1 = (NumberAxis) plot.getRangeAxis(0);
    axis1.setNumberFormatOverride(new DecimalFormat("#,##0"));

    // change axis date format
    ((DateAxis) plot.getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    chart.setBackgroundPaint(Color.WHITE);
    return chart;
}

From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java

public synchronized void setCurrentAverageLatency(long time, int index, double latency) {
    synchronized (LiveMonitorInfo.LOCK) {
        DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
        if (model.getRowCount() <= 2 + (index * ROW_PER_TX_TYPE + 1)) {
            model.addRow(new Object[] { "", "" });
        }/*from w ww .ja  va 2s  . com*/
        model.setValueAt(String.format("%.1f", latency), 2 + (index * ROW_PER_TX_TYPE) + 1, 1);
        if (numTransactionType < index + 1) {
            String newName = "Type " + (index + 1);
            transactionNames.add(newName);
            numTransactionType = index + 1;

            JLabel newLabel = new JLabel(newName);
            JButton renameButton = new JButton("Rename");
            JButton viewSampleButton = new JButton("View Examples");
            //            JButton enableDisableButton;
            //            if (DBSeerGUI.liveDataset.isTransactionEnabled(index))
            //            {
            //               enableDisableButton = new JButton("Disable");
            //            }
            //            else
            //            {
            //               enableDisableButton = new JButton("Enable");
            //            }

            renameButton.addActionListener(this);
            viewSampleButton.addActionListener(this);
            //            enableDisableButton.addActionListener(this);

            transactionTypesPanel.add(newLabel);
            transactionTypesPanel.add(renameButton);
            transactionTypesPanel.add(viewSampleButton);
            //            transactionTypesPanel.add(enableDisableButton);

            transactionLabels.add(newLabel);
            transactionRenameButtons.add(renameButton);
            transactionViewSampleButtons.add(viewSampleButton);
            //            transactionEnableDisableButtons.add(enableDisableButton);

            throughputCollection.addSeries(new TimeSeries(newName, Millisecond.class));
            latencyCollection.addSeries(new TimeSeries(newName, Millisecond.class));

            this.revalidate();
            this.repaint();
        }
        model.setValueAt(
                String.format("Current average latency of '%s' transactions", transactionNames.get(index)),
                2 + (index * ROW_PER_TX_TYPE) + 1, 0);

        if (index < latencyCollection.getSeriesCount()) {
            TimeSeries series = latencyCollection.getSeries(index);
            //            series.add(new Millisecond(), latency);
            series.addOrUpdate(new Millisecond(new Date(time * 1000)), latency);
        }
    }
}

From source file:de.xirp.ui.widgets.panels.LiveChartComposite.java

/**
 * Adds the given key.//from w w w  . j  ava2  s . c o m
 * 
 * @param key
 *          The key.
 */
private void addKey(String key) {
    TimeSeries ts = new TimeSeries(key, Millisecond.class);
    ts.setMaximumItemAge(TIME);
    keySeriesMap.put(key, ts);
    dataset.addSeries(ts);
    pool.addDatapoolReceiveListener(key, listener);
}

From source file:edu.fullerton.viewerplugin.TsPlot.java

private void addTimeSeries(ChanDataBuffer dbuf, boolean compact, TimeSeriesCollection mtds)
        throws LdvTableException {
    String legend = getLegend(dbuf, compact);
    TimeSeries ts;/*ww  w. jav a 2  s .  com*/
    ts = new TimeSeries(legend, Millisecond.class);
    SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC");

    float rate = dbuf.getChanInfo().getRate();
    double msPerSample = 1000 / rate;
    long startMs = TimeAndDate.gps2utc(dbuf.getTimeInterval().getStartGps()) * 1000;
    float[] data = dbuf.getData();
    for (int i = 0; i < dbuf.getDataLength(); i++) {
        long curMs = Math.round(msPerSample * i + startMs);
        Date t = new Date(curMs);
        ts.addOrUpdate(new Millisecond(t, utctz), data[i]);
        if (msPerSample >= 1000) {
            // this plots trend data as stair steps
            long endMs = Math.round(curMs + msPerSample - 1);
            Date t1 = new Date(endMs);
            ts.addOrUpdate(new Millisecond(t1, utctz), data[i]);
        }
    }

    mtds.addSeries(ts);
    if (addLinFit) {
        TimeSeries linTs = LinFit(ts);
        mtds.addSeries(linTs);
    }

}