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

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

Introduction

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

Prototype

public void add(RegularTimePeriod period, Number value) 

Source Link

Document

Adds a new data item to the series and sends a org.jfree.data.general.SeriesChangeEvent to all registered listeners.

Usage

From source file:org.yccheok.jstock.charting.TechnicalAnalysis.java

/**
 * Returns MFI XYDataset for charting purpose.
 *
 * @param chartDatas list of chart data//from   w  w w. j a v a2 s  .c o m
 * @param name name for the XYDataset
 * @param period the duration period
 * @return MFI XYDataset for charting purpose
 */
public static XYDataset createMFI(List<ChartData> chartDatas, String name, int period) {
    if (period <= 0) {
        throw new java.lang.IllegalArgumentException("period must be greater than 0");
    }

    final TimeSeries series = new TimeSeries(name);
    final int num = chartDatas.size();

    final Core core = new Core();
    final int allocationSize = num - core.mfiLookback(period);
    if (allocationSize <= 0) {
        return new TimeSeriesCollection(series);
    }

    final double[] high = new double[num];
    final double[] low = new double[num];
    final double[] close = new double[num];
    final double[] volume = new double[num];
    // Fill up last array.
    for (int i = 0; i < num; i++) {
        high[i] = chartDatas.get(i).highPrice;
        low[i] = chartDatas.get(i).lowPrice;
        close[i] = chartDatas.get(i).lastPrice;
        volume[i] = chartDatas.get(i).volume;
    }

    final double[] output = new double[allocationSize];
    final MInteger outBegIdx = new MInteger();
    final MInteger outNbElement = new MInteger();

    core.mfi(0, num - 1, high, low, close, volume, period, outBegIdx, outNbElement, output);

    for (int i = 0; i < outNbElement.value; i++) {
        series.add(new Day(new Date(chartDatas.get(i + outBegIdx.value).timestamp)), output[i]);
    }

    return new TimeSeriesCollection(series);
}