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

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

Introduction

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

Prototype

public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value) 

Source Link

Document

Adds or updates an item in the times series and sends a SeriesChangeEvent to all registered listeners.

Usage

From source file:in.BBAT.presenter.DualAxisDemo2.java

/**
 * Creates a sample dataset.//w  w  w  .j  a  v  a2  s  . co m
 *
 * @return The dataset.
 */
private XYDataset createDataset2() {

    final TimeSeries s1 = new TimeSeries("CPU", Millisecond.class);
    for (CpuUsageEntity ent : ScreenShotView.testCase.getCpuUsageValues()) {
        s1.addOrUpdate(new Millisecond(new Date(ent.getTime())), ent.getPercent());
    }

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);

    return dataset;

}

From source file:in.BBAT.presenter.DualAxisDemo2.java

/**
 * Creates a sample dataset.//from   w w w . jav a 2 s.  c  o  m
 *
 * @return The dataset.
 */
private XYDataset createDataset1() {

    final TimeSeries s2 = new TimeSeries("Memory", Millisecond.class);
    for (MemoryEntity ent : ScreenShotView.testCase.getMemoryUsageValues()) {
        s2.addOrUpdate(new Millisecond(new Date(ent.getTime())), ent.getPercent());
    }

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s2);

    return dataset;

}

From source file:pfg.graphic.Chart.java

/**
 * Ajoute des donnes  afficher//from w  w w .ja  va2s  .  c o m
 * @param name
 * @param value
 */
public void addData(String name, Double value) {
    if (!init)
        init();

    Date temps = new Date();

    TimeSeries ts = series.get(name);
    if (ts == null) {
        ts = new TimeSeries(name);
        series.put(name, ts);
        dataset.addSeries(ts);
    }
    ts.addOrUpdate(new Millisecond(temps), value);
}

From source file:com.hazelcast.monitor.server.InstanceChartGenerator.java

public JFreeChart generateSizeChart(List<? super InstanceStatistics> list) {
    TimeSeries ts = new TimeSeries("size");
    for (int i = 0; i < list.size(); i++) {
        InstanceStatistics instanceStatistics = (InstanceStatistics) list.get(i);
        ts.addOrUpdate(new Second(instanceStatistics.getCreatedDate()),
                new Double(instanceStatistics.getSize() / (double) 1000));
    }/* w w w  .ja  v  a2  s .  c  o  m*/
    TimeSeriesCollection timeDataset = new TimeSeriesCollection();
    timeDataset.addSeries(ts);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "time", "size (x1000)", timeDataset, true, true,
            true);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0);
    increaseRange(sizeAxis);
    afterPlot(list, chart, plot);
    return chart;
}

From source file:com.hazelcast.monitor.server.InstanceChartGenerator.java

public JFreeChart generateOperationStatsChart(List<? super InstanceStatistics> list) {
    TimeSeries ts = new TimeSeries("operations per second");
    for (int i = 0; i < list.size(); i++) {
        InstanceStatistics instanceStatistics = (InstanceStatistics) list.get(i);
        ts.addOrUpdate(new Second(instanceStatistics.getCreatedDate()),
                (double) instanceStatistics.getTotalOPS() / 1000);
    }/*  w  ww  . j  a v a2 s .c  o  m*/
    TimeSeriesCollection timeDataset = new TimeSeriesCollection();
    timeDataset.addSeries(ts);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "time", "throughput (x1000)", timeDataset, true,
            true, true);
    XYPlot plot = (XYPlot) chart.getPlot();
    increaseRange((NumberAxis) plot.getRangeAxis(0));
    return chart;
}

From source file:org.activequant.util.charting.Chart.java

/**
 * Adds or updates a point in the dataset.
 * /*from  w w  w.ja v a  2  s. c o m*/
 * @param datasetIndex dataset index (zero-based).
 * @param timeStamp time stamp of the event.
 * @param value event value.
 */
public void addSeriesDataItem(int datasetIndex, TimeStamp timeStamp, double value) {
    if (datasetIndex >= datasets.size()) {
        throw new IllegalArgumentException(
                "wrong dataset index: size=" + datasets.size() + ", index=" + datasetIndex);
    }
    TimeSeries ts = datasets.get(datasetIndex);
    ts.addOrUpdate(new Millisecond(timeStamp.getDate()), value);
}

From source file:pt.lsts.neptus.console.plugins.AirOSPeers.java

@Periodic
private void update() {
    if (System.currentTimeMillis() - lastUpdateMillis < seconds * 1000)
        return;// w  ww .j a  v  a2  s  . c o m
    lastUpdateMillis = System.currentTimeMillis();

    Future<String> result = SSHUtil.exec(host, port, credentials.getUsername(), credentials.getPassword(),
            "wstalist");
    try {
        String json = result.get(5, TimeUnit.SECONDS);

        if (logToDisk) {
            DevDataText txt = new DevDataText();
            txt.setValue(json);
            txt.setSrcEnt(ImcMsgManager.getManager().getEntityId());
            txt.setSrc(ImcMsgManager.getManager().getLocalId().intValue());
            LsfMessageLogger.log(txt);
        }

        HashSet<String> series = new HashSet<>();
        for (Object o : tsc.getSeries()) {
            TimeSeries tseries = (TimeSeries) o;
            series.add("" + tseries.getKey());
        }

        for (Station station : new StationList(json).stations) {
            series.remove(nameOf(station));
            process(station);
        }

        for (String name : series) {
            TimeSeries ts = tsc.getSeries(name);
            if (ts != null)
                ts.addOrUpdate(new Millisecond(new Date(System.currentTimeMillis())), null);
        }
    } catch (TimeoutException timeout) {
        NeptusLog.pub().error("Timeout while trying to connect to " + host + ":" + port);
    } catch (Exception e) {
        e.printStackTrace();
        NeptusLog.pub().error(e);
    }
}

From source file:binky.reportrunner.ui.actions.admin.GetAuditChartAction.java

@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String execute() throws Exception {

    // do some stuff and get a chart going
    // DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    List<RunnerHistoryEvent> events = auditService.getSuccessEvents(module, new Date(fromDate),
            new Date(toDate));
    Map<String, TimeSeries> serieses = new HashMap<String, TimeSeries>();
    for (RunnerHistoryEvent e : events) {
        TimeSeries s = serieses.get(e.getMethod());
        if (s == null) {
            s = new TimeSeries(e.getMethod());
            serieses.put(e.getMethod(), s);
        }/*from  ww w.  j a  va 2s .com*/
        s.addOrUpdate(new Millisecond(e.getTimeStamp()), e.getRunTime());
    }
    for (TimeSeries s : serieses.values()) {
        dataSet.addSeries(s);
    }
    chart = ChartFactory.createTimeSeriesChart(module, "", "run time (ms)", dataSet, true, false, false);

    // .createLineChart("","","Run Time (ms)",dataSet,PlotOrientation.VERTICAL,
    // true,false,false);
    XYPlot linePlot = (XYPlot) chart.getPlot();
    linePlot.setDomainGridlinesVisible(true);
    linePlot.setRangeGridlinesVisible(true);
    linePlot.setRangeGridlinePaint(Color.black);
    linePlot.setDomainGridlinePaint(Color.black);
    TextTitle subTitle = new TextTitle("Successful Executions");
    subTitle.setFont(new Font("Arial", Font.ITALIC, 10));
    chart.addSubtitle(subTitle);
    chart.getTitle().setFont(new Font("Arial", Font.BOLD, 12));

    DateAxis axis = (DateAxis) linePlot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy"));

    XYItemRenderer r = linePlot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    return SUCCESS;
}

From source file:DashboardInterface.LaunchGraph.java

public void addDataPoint(long time, float value, TimeSeries series) {
    series.addOrUpdate(new Millisecond(new Date(previousTime)), value);
}

From source file:DataCharts.Chart.java

/**
 * Creates a dataset, consisting customers per area code
 * Methods are for display purposes at this point and may be refactored and 
 * modified based on necessity/*from www.  j a  va2  s .  co  m*/
 */
private XYDataset createXYDataset(ArrayList<YearData> locs) {

    try {
        ResultSet locations = db.selectDataColumn("customer", "*");
        TimeSeriesCollection dataset = new TimeSeriesCollection();

        Calendar defCal = Calendar.getInstance();
        defCal.set(2015, 1, 1);
        int defMonthNum = defCal.get(Calendar.MONTH);
        TimeSeries defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        Month defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        defCal = Calendar.getInstance();
        defCal.set(2015, 6, 6);
        defMonthNum = defCal.get(Calendar.MONTH);
        defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        dataset.addSeries(defTime);
        while (locations.next()) {

            ResultSet jobDates = db.selectDataColumn("jobs", "date", locations.getString(2), "CustomerID");
            TimeSeries time = new TimeSeries("" + locations.getInt(7));
            int n = 0;
            Month month = null;
            while (jobDates.next()) {
                if (n == 0) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(jobDates.getDate(1));
                    int monthNum = cal.get(Calendar.MONTH);
                    month = new Month(monthNum, 2015);
                }
                n++;

            }
            if (month != null) {
                time.addOrUpdate(month, n);
                dataset.addSeries(time);
            }
        }
        return dataset;
    } catch (SQLException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}