Example usage for org.jfree.data.time Hour Hour

List of usage examples for org.jfree.data.time Hour Hour

Introduction

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

Prototype

public Hour(int hour, int day, int month, int year) 

Source Link

Document

Creates a new hour.

Usage

From source file:org.jfree.chart.demo.MarkerDemo2.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Marker Demo 2", "X", "Temperature", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeTickBandPaint(new Color(240, 240, 240));
    PeriodAxis periodaxis = new PeriodAxis(null, new Hour(0, 30, 6, 2005), new Hour(23, 30, 6, 2005));
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Hour.class,
            new SimpleDateFormat("HH"));
    aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class,
            new SimpleDateFormat("dd-MMM"));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);//from   ww w. ja  v  a 2s . co m
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 100D);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.green);
    xyitemrenderer.setSeriesStroke(0, new BasicStroke(2.0F));
    ValueMarker valuemarker = new ValueMarker(80D);
    valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    valuemarker.setPaint(Color.red);
    valuemarker.setStroke(new BasicStroke(2.0F));
    valuemarker.setLabel("Temperature Threshold");
    valuemarker.setLabelFont(new Font("SansSerif", 0, 11));
    valuemarker.setLabelPaint(Color.red);
    valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
    xyplot.addRangeMarker(valuemarker);
    Hour hour = new Hour(18, 30, 6, 2005);
    Hour hour1 = new Hour(20, 30, 6, 2005);
    double d = hour.getFirstMillisecond();
    double d1 = hour1.getFirstMillisecond();
    IntervalMarker intervalmarker = new IntervalMarker(d, d1);
    intervalmarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    intervalmarker.setPaint(new Color(150, 150, 255));
    intervalmarker.setLabel("Automatic Cooling");
    intervalmarker.setLabelFont(new Font("SansSerif", 0, 11));
    intervalmarker.setLabelPaint(Color.blue);
    intervalmarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    intervalmarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    xyplot.addDomainMarker(intervalmarker, Layer.BACKGROUND);
    ValueMarker valuemarker1 = new ValueMarker(d, Color.blue, new BasicStroke(2.0F));
    ValueMarker valuemarker2 = new ValueMarker(d1, Color.blue, new BasicStroke(2.0F));
    xyplot.addDomainMarker(valuemarker1, Layer.BACKGROUND);
    xyplot.addDomainMarker(valuemarker2, Layer.BACKGROUND);
    return jfreechart;
}

From source file:org.jfree.chart.demo.MarkerDemo2.java

private static XYDataset createDataset() {
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    TimeSeries timeseries = new TimeSeries("Temperature");
    timeseries.add(new Hour(0, 30, 6, 2005), 45.299999999999997D);
    timeseries.add(new Hour(1, 30, 6, 2005), 48.899999999999999D);
    timeseries.add(new Hour(2, 30, 6, 2005), 52.100000000000001D);
    timeseries.add(new Hour(3, 30, 6, 2005), 44.799999999999997D);
    timeseries.add(new Hour(4, 30, 6, 2005), 49.899999999999999D);
    timeseries.add(new Hour(5, 30, 6, 2005), 55.5D);
    timeseries.add(new Hour(6, 30, 6, 2005), 58.200000000000003D);
    timeseries.add(new Hour(7, 30, 6, 2005), 58.100000000000001D);
    timeseries.add(new Hour(8, 30, 6, 2005), 63.700000000000003D);
    timeseries.add(new Hour(9, 30, 6, 2005), 66.299999999999997D);
    timeseries.add(new Hour(10, 30, 6, 2005), 69.799999999999997D);
    timeseries.add(new Hour(11, 30, 6, 2005), 70.099999999999994D);
    timeseries.add(new Hour(12, 30, 6, 2005), 72.400000000000006D);
    timeseries.add(new Hour(13, 30, 6, 2005), 69.700000000000003D);
    timeseries.add(new Hour(14, 30, 6, 2005), 68.599999999999994D);
    timeseries.add(new Hour(15, 30, 6, 2005), 70.900000000000006D);
    timeseries.add(new Hour(16, 30, 6, 2005), 73.400000000000006D);
    timeseries.add(new Hour(17, 30, 6, 2005), 77.5D);
    timeseries.add(new Hour(18, 30, 6, 2005), 82.900000000000006D);
    timeseries.add(new Hour(19, 30, 6, 2005), 62.100000000000001D);
    timeseries.add(new Hour(20, 30, 6, 2005), 37.299999999999997D);
    timeseries.add(new Hour(21, 30, 6, 2005), 40.700000000000003D);
    timeseries.add(new Hour(22, 30, 6, 2005), 44.200000000000003D);
    timeseries.add(new Hour(23, 30, 6, 2005), 49.799999999999997D);
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < clusters.size(); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Sensor> member_time_series = current_cluster.getMembership();

        for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) {
            final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class);

            Sensor current_series = (Sensor) iterator.next();

            for (int j = 0; j < current_series.getDimensions(); j++) {
                LocalDateTime current_record_time = current_series.getInitial_record_time().plusHours(j);
                s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                        current_record_time.getMonthValue(), current_record_time.getYear()),
                        current_series.getMeasurement(j));
            }/*from  ww  w .j a  v  a 2  s. c  o  m*/

            dataset.addSeries(s1);
        }
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:org.jfree.data.time.HourTest.java

/**
 * Two objects that are equal are required to return the same hashCode.
 *///from   ww  w. j av  a2s  . c o  m
@Test
public void testHashcode() {
    Hour h1 = new Hour(7, 9, 10, 1999);
    Hour h2 = new Hour(7, 9, 10, 1999);
    assertTrue(h1.equals(h2));
    int hash1 = h1.hashCode();
    int hash2 = h2.hashCode();
    assertEquals(hash1, hash2);
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Sensor> sensors) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < sensors.size(); i++) {
        Sensor current_sensor = sensors.get(i);

        final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class);

        for (int j = 0; j < current_sensor.getDimensions(); j++) {
            LocalDateTime current_record_time = current_sensor.getInitial_record_time().plusHours(j);
            s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                    current_record_time.getMonthValue(), current_record_time.getYear()),
                    current_sensor.getMeasurement(j));
        }/*  ww  w  .  j av a 2 s  . c  om*/

        dataset.addSeries(s1);
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:org.jfree.data.time.HourTest.java

/**
 * The {@link Hour} class is immutable, so should not be {@link Cloneable}.
 *//*w ww .j a v  a  2s. co  m*/
@Test
public void testNotCloneable() {
    Hour h = new Hour(7, 9, 10, 1999);
    assertFalse(h instanceof Cloneable);
}

From source file:org.jfree.data.time.HourTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from w  w w . ja  v a  2s . c o m*/
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Hour h = new Hour(15, 1, 4, 2006);
    assertEquals(1143900000000L, h.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.junit.HourTest.java

/**
 * Two objects that are equal are required to return the same hashCode.
 *///from   w  w w. ja v  a  2 s  . co m
public void testHashcode() {
    Hour h1 = new Hour(7, 9, 10, 1999);
    Hour h2 = new Hour(7, 9, 10, 1999);
    assertTrue(h1.equals(h2));
    int hash1 = h1.hashCode();
    int hash2 = h2.hashCode();
    assertEquals(hash1, hash2);
}

From source file:org.jfree.data.time.HourTest.java

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *//* www.j av a2s.com*/
@Test
public void testGetFirstMillisecondWithTimeZone() {
    Hour h = new Hour(15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    assertEquals(-623293200000L, h.getFirstMillisecond(zone));

    // try null calendar
    boolean pass = false;
    try {
        h.getFirstMillisecond((TimeZone) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:org.jfree.data.time.junit.HourTest.java

/**
 * The {@link Hour} class is immutable, so should not be {@link Cloneable}.
 *//*from  www .  j  ava2s  .c  om*/
public void testNotCloneable() {
    Hour h = new Hour(7, 9, 10, 1999);
    assertFalse(h instanceof Cloneable);
}