org.jfree.data.xy.OHLCDataset Java Examples

The following examples show how to use org.jfree.data.xy.OHLCDataset. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #2
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
                                                String timeAxisLabel,
                                                String valueAxisLabel,
                                                OHLCDataset dataset,
                                                boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #3
Source File: ChartFactory.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
                                            String timeAxisLabel,
                                            String valueAxisLabel,
                                            OHLCDataset dataset,
                                            boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #4
Source File: ChartFactory.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #5
Source File: ChartFactory.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
                                                String timeAxisLabel,
                                                String valueAxisLabel,
                                                OHLCDataset dataset,
                                                boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #6
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
                                            String timeAxisLabel,
                                            String valueAxisLabel,
                                            OHLCDataset dataset,
                                            boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #7
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #8
Source File: HighLowItemLabelGenerator.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a tooltip text item for a particular item within a series.
 *
 * @param dataset  the dataset.
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.
 */
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
    if (!(dataset instanceof OHLCDataset)) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    OHLCDataset d = (OHLCDataset) dataset;
    Number high = d.getHigh(series, item);
    Number low = d.getLow(series, item);
    Number open = d.getOpen(series, item);
    Number close = d.getClose(series, item);
    Number x = d.getX(series, item);
    sb.append(d.getSeriesKey(series).toString());
    if (x != null) {
        Date date = new Date(x.longValue());
        sb.append("--> Date=").append(this.dateFormatter.format(date));
        if (high != null) {
            sb.append(" High=");
            sb.append(this.numberFormatter.format(high.doubleValue()));
        }
        if (low != null) {
            sb.append(" Low=");
            sb.append(this.numberFormatter.format(low.doubleValue()));
        }
        if (open != null) {
            sb.append(" Open=");
            sb.append(this.numberFormatter.format(open.doubleValue()));
        }
        if (close != null) {
            sb.append(" Close=");
            sb.append(this.numberFormatter.format(close.doubleValue()));
        }
    }
    return sb.toString();
}
 
Example #9
Source File: HighLowItemLabelGenerator.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a tooltip text item for a particular item within a series.
 *
 * @param dataset  the dataset.
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.
 */
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
    if (!(dataset instanceof OHLCDataset)) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    OHLCDataset d = (OHLCDataset) dataset;
    Number high = d.getHigh(series, item);
    Number low = d.getLow(series, item);
    Number open = d.getOpen(series, item);
    Number close = d.getClose(series, item);
    Number x = d.getX(series, item);
    sb.append(d.getSeriesKey(series).toString());
    if (x != null) {
        Date date = new Date(x.longValue());
        sb.append("--> Date=").append(this.dateFormatter.format(date));
        if (high != null) {
            sb.append(" High=");
            sb.append(this.numberFormatter.format(high.doubleValue()));
        }
        if (low != null) {
            sb.append(" Low=");
            sb.append(this.numberFormatter.format(low.doubleValue()));
        }
        if (open != null) {
            sb.append(" Open=");
            sb.append(this.numberFormatter.format(open.doubleValue()));
        }
        if (close != null) {
            sb.append(" Close=");
            sb.append(this.numberFormatter.format(close.doubleValue()));
        }
    }
    return sb.toString();
}
 
Example #10
Source File: ChartFactory.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #11
Source File: CandlestickRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
        // Absolute value, since the relative x
        // positions are reversed for horizontal orientation

    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount();
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series);
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}
 
Example #12
Source File: CandlestickRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
        // Absolute value, since the relative x
        // positions are reversed for horizontal orientation

    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount();
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series);
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}
 
Example #13
Source File: CandlestickRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
        // Absolute value, since the relative x
        // positions are reversed for horizontal orientation

    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount();
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series);
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}
 
Example #14
Source File: CandlestickRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method 
 * will be called before the first item is rendered, giving the renderer 
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to 
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
public XYItemRendererState initialise(Graphics2D g2,
                                      Rectangle2D dataArea,
                                      XYPlot plot,
                                      XYDataset dataset,
                                      PlotRenderingInfo info) {
      
    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1); 
        // Absolute value, since the relative x 
        // positions are reversed for horizontal orientation
    
    // calculate the highest volume in the dataset... 
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount(); 
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series); 
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }
                
            }    
        }
    }
    
    return new XYItemRendererState(info);
}
 
Example #15
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #16
Source File: HighLowItemLabelGenerator.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a tooltip text item for a particular item within a series.
 *
 * @param dataset  the dataset.
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.
 */
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
    if (!(dataset instanceof OHLCDataset)) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    OHLCDataset d = (OHLCDataset) dataset;
    Number high = d.getHigh(series, item);
    Number low = d.getLow(series, item);
    Number open = d.getOpen(series, item);
    Number close = d.getClose(series, item);
    Number x = d.getX(series, item);
    sb.append(d.getSeriesKey(series).toString());
    if (x != null) {
        Date date = new Date(x.longValue());
        sb.append("--> Date=").append(this.dateFormatter.format(date));
        if (high != null) {
            sb.append(" High=");
            sb.append(this.numberFormatter.format(high.doubleValue()));
        }
        if (low != null) {
            sb.append(" Low=");
            sb.append(this.numberFormatter.format(low.doubleValue()));
        }
        if (open != null) {
            sb.append(" Open=");
            sb.append(this.numberFormatter.format(open.doubleValue()));
        }
        if (close != null) {
            sb.append(" Close=");
            sb.append(this.numberFormatter.format(close.doubleValue()));
        }
    }
    return sb.toString();
}
 
Example #17
Source File: JGenProg2017_0047_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the xy dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateXYRangeBounds(XYDataset dataset) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();
    for (int series = 0; series < seriesCount; series++) {
        int itemCount = dataset.getItemCount(series);
        for (int item = 0; item < itemCount; item++) {
            double lvalue;
            double uvalue;
            if (dataset instanceof IntervalXYDataset) {
                IntervalXYDataset intervalXYData 
                    = (IntervalXYDataset) dataset;
                lvalue = intervalXYData.getStartYValue(series, item);
                uvalue = intervalXYData.getEndYValue(series, item);
            }
            else if (dataset instanceof OHLCDataset) {
                OHLCDataset highLowData = (OHLCDataset) dataset;
                lvalue = highLowData.getLowValue(series, item);
                uvalue = highLowData.getHighValue(series, item);
            }
            else {
                lvalue = dataset.getYValue(series, item);
                uvalue = lvalue;
            }
            if (!Double.isNaN(lvalue)) {
                minimum = Math.min(minimum, lvalue);
            }
            if (!Double.isNaN(uvalue)) {     
                maximum = Math.max(maximum, uvalue);
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #18
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #19
Source File: ChartFactory.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #20
Source File: JGenProg2017_0047_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is 
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).  
 * Otherwise, it involves iterating over the entire data-set.  Returns 
 * <code>null</code> if all the data values in the dataset are 
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData 
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #21
Source File: DatasetUtilities.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example #22
Source File: DatasetUtilities.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is 
 * easy if the dataset implements the {@link RangeInfo} interface (a good 
 * idea if there is an efficient way to determine the maximum value).  
 * Otherwise, it involves iterating over the entire data-set.  Returns 
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData 
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example #23
Source File: DatasetUtilities.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #24
Source File: DatasetUtilities.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #25
Source File: ChartFactory.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart
 * with a special timeline. This timeline can be a
 * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday
 * through Friday timeline that will remove Saturdays and Sundays from
 * the axis.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param timeline  the timeline.
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        Timeline timeline, boolean legend) {

    DateAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setTimeline(timeline);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #26
Source File: DatasetUtilities.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example #27
Source File: DatasetUtilities.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #28
Source File: JGenProg2017_0047_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is 
 * easy if the dataset implements the {@link RangeInfo} interface (a good 
 * idea if there is an efficient way to determine the maximum value).  
 * Otherwise, it involves iterating over the entire data-set.  Returns 
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData 
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example #29
Source File: HighLowItemLabelGenerator.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a tooltip text item for a particular item within a series.
 *
 * @param dataset  the dataset.
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.
 */
public String generateToolTip(XYDataset dataset, int series, int item) {

    String result = null;

    if (dataset instanceof OHLCDataset) {
        OHLCDataset d = (OHLCDataset) dataset;
        Number high = d.getHigh(series, item);
        Number low = d.getLow(series, item);
        Number open = d.getOpen(series, item);
        Number close = d.getClose(series, item);
        Number x = d.getX(series, item);

        result = d.getSeriesKey(series).toString();

        if (x != null) {
            Date date = new Date(x.longValue());
            result = result + "--> Date=" + this.dateFormatter.format(date);
            if (high != null) {
                result = result + " High=" 
                         + this.numberFormatter.format(high.doubleValue());
            }
            if (low != null) {
                result = result + " Low=" 
                         + this.numberFormatter.format(low.doubleValue());
            }
            if (open != null) {
                result = result + " Open=" 
                         + this.numberFormatter.format(open.doubleValue());
            }
            if (close != null) {
                result = result + " Close=" 
                         + this.numberFormatter.format(close.doubleValue());
            }
        }

    }

    return result;

}
 
Example #30
Source File: DatasetUtilities.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}