Example usage for org.jfree.data.time.ohlc OHLCSeries OHLCSeries

List of usage examples for org.jfree.data.time.ohlc OHLCSeries OHLCSeries

Introduction

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

Prototype

public OHLCSeries(Comparable key) 

Source Link

Document

Creates a new empty series.

Usage

From source file:com.bdb.weather.display.summary.HighLowPanel.java

@SuppressWarnings("LeakingThisInConstructor")
public HighLowPanel(String title, SummaryInterval interval, ViewLauncher launcher, SummarySupporter supporter,
        ValueAxis rangeAxis, String domainAxisLabel, SeriesInfo<T>[] seriesList, NumberFormat format) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    this.launcher = launcher;
    this.supporter = supporter;

    chart = ChartFactory.createHighLowChart(title, domainAxisLabel, "", seriesCollection, true);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    plot = (XYPlot) chart.getPlot();/*from w w  w.j  a va2 s. c  om*/
    renderer = (HighLowRenderer) plot.getRenderer();
    renderer.setDrawCloseTicks(false);

    plot.setRangeAxis(rangeAxis);

    dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setDateFormatOverride(interval.getLegacyFormat());
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    //dateAxis.setTickUnit(interval.getDateTickUnit());
    //dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 2));

    ChartViewer chartViewer = new ChartViewer(chart);
    chartViewer.addChartMouseListener(this);
    chartViewer.setPrefSize(500, 300);

    series = new OHLCSeries[seriesList.length];

    for (int i = 0; i < seriesList.length; i++) {
        series[i] = new OHLCSeries(seriesList[i].getSeriesName());
        seriesCollection.addSeries(series[i]);
    }

    seriesInfo = Arrays.copyOf(seriesList, seriesList.length);

    TableColumn<SummaryRecord, String> column = new TableColumn<>("Date");
    column.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));

    dataTable.getColumns().add(column);

    String headingPrefix[] = { HIGH_COL_HEADING, LOW_COL_HEADING, AVG_COL_HEADING };

    for (SeriesInfo<T> seriesColumn : seriesList) {
        for (String heading : headingPrefix) {
            column = new TableColumn<>(heading + " - " + seriesColumn.getSeriesName());
            column.setCellValueFactory(seriesColumn);
            column.setUserData(heading);
            dataTable.getColumns().add(column);
        }
    }

    this.setTabContents(chartViewer, dataTable);

    HighLowItemLabelGenerator ttg = new HiLoItemLabelGenerator(interval.getLegacyFormat(), format);
    plot.getRenderer().setBaseToolTipGenerator(ttg);
}

From source file:org.jfree.data.time.ohlc.OHLCSeriesTest.java

/**
 * A simple check that the maximumItemCount attribute is working.
 *//*  ww  w. j  a  va2  s . c  o m*/
@Test
public void testSetMaximumItemCount() {
    OHLCSeries s1 = new OHLCSeries("s1");
    assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount());
    s1.setMaximumItemCount(2);
    assertEquals(2, s1.getMaximumItemCount());
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2);
    s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3);
    assertEquals(new Year(2007), s1.getPeriod(0));
    assertEquals(new Year(2008), s1.getPeriod(1));
}

From source file:org.jfree.data.time.ohlc.OHLCSeriesTest.java

/**
 * Check that the maximum item count can be applied retrospectively.
 *//*w w w . j av  a 2s. co m*/
@Test
public void testSetMaximumItemCount2() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2);
    s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3);
    s1.setMaximumItemCount(2);
    assertEquals(new Year(2007), s1.getPeriod(0));
    assertEquals(new Year(2008), s1.getPeriod(1));
}

From source file:org.jfree.data.time.ohlc.OHLCSeriesCollectionTest.java

/**
 * A simple check for the removeAllSeries() method.
 *//*from   www  .  j a  v a2  s. c o m*/
@Test
public void testRemoveAllSeries() {
    OHLCSeriesCollection c1 = new OHLCSeriesCollection();
    c1.addChangeListener(this);

    // there should be no change event when clearing an empty series
    this.lastEvent = null;
    c1.removeAllSeries();
    assertNull(this.lastEvent);

    OHLCSeries s1 = new OHLCSeries("Series 1");
    OHLCSeries s2 = new OHLCSeries("Series 2");
    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.removeAllSeries();
    assertEquals(0, c1.getSeriesCount());
    assertNotNull(this.lastEvent);
    this.lastEvent = null; // clean up
}

From source file:org.jfree.data.time.ohlc.OHLCSeriesTest.java

/**
 * Some checks for the clear() method.//w  w  w.ja  va 2  s. c o  m
 */
@Test
public void testClear() {
    OHLCSeries s1 = new OHLCSeries("S1");
    s1.addChangeListener(this);
    s1.clear();
    assertNull(this.lastEvent);
    assertTrue(s1.isEmpty());
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    assertFalse(s1.isEmpty());
    s1.clear();
    assertNotNull(this.lastEvent);
    assertTrue(s1.isEmpty());
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initOHLCSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) {

    BarDefinitionVO barDefinition = (BarDefinitionVO) seriesDefinition;
    OHLCSeriesCollection ohlcSeriesCollection = (OHLCSeriesCollection) dataset;
    ohlcSeriesCollection.setXPosition(TimePeriodAnchor.START);

    // create the TimeSeries
    OHLCSeries series = new OHLCSeries(barDefinition.getLabel());
    ohlcSeriesCollection.addSeries(series);
    this.bars.put(barDefinition.getSecurityId(), series);

    // get the seriesNumber & color
    final int seriesNumber = ohlcSeriesCollection.getSeriesCount() - 1;

    // configure the renderer
    final CandlestickRenderer renderer = (CandlestickRenderer) getPlot().getRenderer(datasetNumber);
    renderer.setSeriesPaint(seriesNumber, getColor(barDefinition.getColor()));
    renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected());
    renderer.setAutoWidthMethod(HideableCandlestickRenderer.WIDTHMETHOD_SMALLEST);

    // add the menu item
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel());
    menuItem.setSelected(seriesDefinition.isSelected());
    menuItem.addActionListener(new ActionListener() {
        @Override/*from w w  w  .j  a  v  a2s  . c o  m*/
        public void actionPerformed(ActionEvent e) {
            resetAxis();
            renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected(), true);
            initAxis();
        }
    });
    this.getPopupMenu().add(menuItem);
}