Example usage for org.jfree.data.category SlidingCategoryDataset setFirstCategoryIndex

List of usage examples for org.jfree.data.category SlidingCategoryDataset setFirstCategoryIndex

Introduction

In this page you can find the example usage for org.jfree.data.category SlidingCategoryDataset setFirstCategoryIndex.

Prototype

public void setFirstCategoryIndex(int first) 

Source Link

Document

Sets the index of the first category that should be used from the underlying dataset, and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.fhaes.fhrecorder.view.ColorBarGraph.java

/**
 * Updates the data of the chart./*from   www  .  j a v  a 2s  .  c o  m*/
 * 
 * @param years the data.
 * @param savePosition true to save the position, else false.
 */
public void updateChartData(List<YearSummary> years, boolean savePosition) {

    SlidingCategoryDataset dataset = (SlidingCategoryDataset) createDataset(years);
    if (savePosition && years.size() > 0) {
        int index = ((SlidingCategoryDataset) getChart().getCategoryPlot().getDataset())
                .getFirstCategoryIndex();
        dataset.setFirstCategoryIndex(index);
    }
    getChart().getCategoryPlot().setDataset(dataset);
}

From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java

/**
 * Some checks for the getColumnKeys() method.
 *///from  w w  w .j  a v a 2  s .  c o m
@Test
public void testGetColumnKeys() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.0, "R1", "C1");
    underlying.addValue(2.0, "R1", "C2");
    underlying.addValue(3.0, "R1", "C3");
    underlying.addValue(4.0, "R1", "C4");
    SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2);
    List keys = dataset.getColumnKeys();
    assertTrue(keys.contains("C2"));
    assertTrue(keys.contains("C3"));
    assertEquals(2, keys.size());

    dataset.setFirstCategoryIndex(3);
    keys = dataset.getColumnKeys();
    assertTrue(keys.contains("C4"));
    assertEquals(1, keys.size());
}

From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java

/**
 * Some checks for the getColumnCount() method.
 *//*from w w  w  .j a v a2  s.c  o  m*/
@Test
public void testGetColumnCount() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 10, 2);
    assertEquals(0, dataset.getColumnCount());
    underlying.addValue(1.0, "R1", "C1");
    assertEquals(0, dataset.getColumnCount());
    underlying.addValue(1.0, "R1", "C2");
    assertEquals(0, dataset.getColumnCount());
    dataset.setFirstCategoryIndex(0);
    assertEquals(2, dataset.getColumnCount());
    underlying.addValue(1.0, "R1", "C3");
    assertEquals(2, dataset.getColumnCount());
    dataset.setFirstCategoryIndex(2);
    assertEquals(1, dataset.getColumnCount());
    underlying.clear();
    assertEquals(0, dataset.getColumnCount());
}

From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java

/**
 * Some checks for the equals() method./*w w w . ja  va2 s  .c o  m*/
 */
@Test
public void testEquals() {
    DefaultCategoryDataset u1 = new DefaultCategoryDataset();
    u1.addValue(1.0, "R1", "C1");
    u1.addValue(2.0, "R1", "C2");
    SlidingCategoryDataset d1 = new SlidingCategoryDataset(u1, 0, 5);
    DefaultCategoryDataset u2 = new DefaultCategoryDataset();
    u2.addValue(1.0, "R1", "C1");
    u2.addValue(2.0, "R1", "C2");
    SlidingCategoryDataset d2 = new SlidingCategoryDataset(u2, 0, 5);
    assertTrue(d1.equals(d2));

    d1.setFirstCategoryIndex(1);
    assertFalse(d1.equals(d2));
    d2.setFirstCategoryIndex(1);
    assertTrue(d1.equals(d2));

    d1.setMaximumCategoryCount(99);
    assertFalse(d1.equals(d2));
    d2.setMaximumCategoryCount(99);
    assertTrue(d1.equals(d2));

    u1.addValue(3.0, "R1", "C3");
    assertFalse(d1.equals(d2));
    u2.addValue(3.0, "R1", "C3");
    assertTrue(d1.equals(d2));
}

From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java

/**
 * This method updates the data in the graph which forces the graph to redraw.
 * /*from  w  w  w.  j a v  a2  s. com*/
 * @param inData This is the list of the incoming YearSummary objects. It is the data used to update the graphs.
 * @param savePosition When savePosition is set to true then this method will automatically scroll to the section of the graph that was
 *            viewable before calling this method. Otherwise when savePosition is false, the graph will scroll to the first year.
 */
public void updateChartData(List<YearSummary> inData, boolean savePosition) {

    SlidingCategoryDataset eventsDataset = (SlidingCategoryDataset) createEventsDataset(inData);
    SlidingCategoryDataset recordersDataset = (SlidingCategoryDataset) createRecordersDataset(inData);
    SlidingCategoryDataset samplesDataset = (SlidingCategoryDataset) createSamplesDataset(inData);
    if (savePosition && inData.size() > 0) {
        int index = ((SlidingCategoryDataset) getChart().getCategoryPlot().getDataset())
                .getFirstCategoryIndex();
        eventsDataset.setFirstCategoryIndex(index);
        recordersDataset.setFirstCategoryIndex(index);
        samplesDataset.setFirstCategoryIndex(index);
    }
    getChart().getCategoryPlot().setDataset(0, eventsDataset);
    // Temporarily removing recorders dataset
    // getChart().getCategoryPlot().setDataset(1, recordersDataset);
    getChart().getCategoryPlot().setDataset(1, samplesDataset);

    updateMaximumRangeValue(inData);
}