org.jfree.chart.util.RelativeDateFormat Java Examples

The following examples show how to use org.jfree.chart.util.RelativeDateFormat. 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: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test that we can configure the RelativeDateFormat to show
 * hh:mm:ss.
 */
public void test2033092() {
    RelativeDateFormat rdf = new RelativeDateFormat();
    rdf.setShowZeroDays(false);
    rdf.setShowZeroHours(false);
    rdf.setMinuteSuffix(":");
    rdf.setHourSuffix(":");
    rdf.setSecondSuffix("");
    DecimalFormat hoursFormatter = new DecimalFormat();
    hoursFormatter.setMaximumFractionDigits(0);
    hoursFormatter.setMaximumIntegerDigits(2);
    hoursFormatter.setMinimumIntegerDigits(2);
    rdf.setHourFormatter(hoursFormatter);
    DecimalFormat minsFormatter = new DecimalFormat();
    minsFormatter.setMaximumFractionDigits(0);
    minsFormatter.setMaximumIntegerDigits(2);
    minsFormatter.setMinimumIntegerDigits(2);
    rdf.setMinuteFormatter(minsFormatter);
    DecimalFormat secondsFormatter = new DecimalFormat();
    secondsFormatter.setMaximumFractionDigits(0);
    secondsFormatter.setMaximumIntegerDigits(2);
    secondsFormatter.setMinimumIntegerDigits(2);
    rdf.setSecondFormatter(secondsFormatter);
    String s = rdf.format(new Date(2 * 60L * 60L * 1000L + 122500L));
    assertEquals("02:02:02", s);
}
 
Example #2
Source File: LineChartBuilder.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the X axis to display time relative to the given start time.
 */
// for relative time, format the x axis differently
// the data _does not_ change
public static void setRelativeAxis(JFreeChart chart, long startTime) {
    if (chart != null) {
        RelativeDateFormat format = new RelativeDateFormat(startTime);
        // : separators
        format.setHourSuffix(":");
        format.setMinuteSuffix(":");
        format.setSecondSuffix("");

        // zero pad minutes and seconds
        DecimalFormat padded = new DecimalFormat("00");
        format.setMinuteFormatter(padded);
        format.setSecondFormatter(padded);

        XYPlot plot = chart.getXYPlot();

        ((DateAxis) plot.getDomainAxis()).setDateFormatOverride(format);
    }
}
 
Example #3
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashCode() {
    RelativeDateFormat df1 = new RelativeDateFormat(123L);
    RelativeDateFormat df2 = new RelativeDateFormat(123L);
    assertTrue(df1.equals(df2));
    int h1 = df1.hashCode();
    int h2 = df2.hashCode();
    assertEquals(h1, h2);
}
 
Example #4
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for negative dates.
 */
public void testNegative() {
    NumberFormat nf = new DecimalFormat("0");
    RelativeDateFormat df1 = new RelativeDateFormat();
    df1.setSecondFormatter(nf);
    assertEquals("-0h0m1s", df1.format(new Date(-1000L)));
}
 
Example #5
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashCode() {
    RelativeDateFormat df1 = new RelativeDateFormat(123L);
    RelativeDateFormat df2 = new RelativeDateFormat(123L);
    assertTrue(df1.equals(df2));
    int h1 = df1.hashCode();
    int h2 = df2.hashCode();
    assertEquals(h1, h2);
}
 
Example #6
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for negative dates.
 */
public void testNegative() {
    NumberFormat nf = new DecimalFormat("0");
    RelativeDateFormat df1 = new RelativeDateFormat();
    df1.setSecondFormatter(nf);
    assertEquals("-0h0m1s", df1.format(new Date(-1000L)));
}
 
Example #7
Source File: KafkaFT.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
private static JFreeChart createChart(XYDataset xydataset) {
	JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Flink Exactly-Once on Kafka with YARN Chaos Monkey", "Date", "Value", xydataset, true, true, false);
	XYPlot xyplot = (XYPlot) jfreechart.getPlot();

	XYLineAndShapeRenderer r0 = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

	// draw data points as points
	r0.setSeriesShapesVisible(2, true);
	r0.setSeriesLinesVisible(2, true);
	// order elements as assed
	xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

	DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();

	Number first = xydataset.getX(0, 0);
	Minute minute = new Minute(new Date((Long)first));
	System.out.println("first = "+first);
	RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
	relativedateformat.setSecondFormatter(new DecimalFormat("00"));
	dateaxis.setDateFormatOverride(relativedateformat);


	//dateaxis.setDateFormatOverride(new SimpleDateFormat("mm:ss"));
	ValueAxis valueaxis = xyplot.getRangeAxis();
	valueaxis.setAutoRangeMinimumSize(1.0D);
	valueaxis.setLabel("Elements/Core");

	xyplot.getRenderer().setSeriesPaint(2, ChartColor.DARK_MAGENTA);
	return jfreechart;
}
 
Example #8
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some checks for the formatting.
 */
public void testFormat() {
    RelativeDateFormat rdf = new RelativeDateFormat();
    String s = rdf.format(new Date(2 * 60L * 60L * 1000L + 122500L));
    assertEquals("2h2m2.500s", s);
}
 
Example #9
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check that the equals() method can distinguish all fields.
 */
public void testEquals() {
    RelativeDateFormat df1 = new RelativeDateFormat();
    RelativeDateFormat df2 = new RelativeDateFormat();
    assertEquals(df1, df2);

    df1.setBaseMillis(123L);
    assertFalse(df1.equals(df2));
    df2.setBaseMillis(123L);
    assertTrue(df1.equals(df2));

    df1.setDayFormatter(new DecimalFormat("0%"));
    assertFalse(df1.equals(df2));
    df2.setDayFormatter(new DecimalFormat("0%"));
    assertTrue(df1.equals(df2));

    df1.setDaySuffix("D");
    assertFalse(df1.equals(df2));
    df2.setDaySuffix("D");
    assertTrue(df1.equals(df2));

    df1.setHourFormatter(new DecimalFormat("0%"));
    assertFalse(df1.equals(df2));
    df2.setHourFormatter(new DecimalFormat("0%"));
    assertTrue(df1.equals(df2));

    df1.setHourSuffix("H");
    assertFalse(df1.equals(df2));
    df2.setHourSuffix("H");
    assertTrue(df1.equals(df2));

    df1.setMinuteFormatter(new DecimalFormat("0%"));
    assertFalse(df1.equals(df2));
    df2.setMinuteFormatter(new DecimalFormat("0%"));
    assertTrue(df1.equals(df2));

    df1.setMinuteSuffix("M");
    assertFalse(df1.equals(df2));
    df2.setMinuteSuffix("M");
    assertTrue(df1.equals(df2));

    df1.setSecondSuffix("S");
    assertFalse(df1.equals(df2));
    df2.setSecondSuffix("S");
    assertTrue(df1.equals(df2));

    df1.setShowZeroDays(!df1.getShowZeroDays());
    assertFalse(df1.equals(df2));
    df2.setShowZeroDays(!df2.getShowZeroDays());
    assertTrue(df1.equals(df2));

    df1.setSecondFormatter(new DecimalFormat("0.0"));
    assertFalse(df1.equals(df2));
    df2.setSecondFormatter(new DecimalFormat("0.0"));
    assertTrue(df1.equals(df2));
}
 
Example #10
Source File: RelativeDateFormatTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check that the equals() method can distinguish all fields.
 */
public void testEquals() {
    RelativeDateFormat df1 = new RelativeDateFormat();
    RelativeDateFormat df2 = new RelativeDateFormat();
    assertEquals(df1, df2);
    
    df1.setBaseMillis(123L);
    assertFalse(df1.equals(df2));
    df2.setBaseMillis(123L);
    assertTrue(df1.equals(df2));
    
    df1.setDaySuffix("D");
    assertFalse(df1.equals(df2));
    df2.setDaySuffix("D");
    assertTrue(df1.equals(df2));
    
    df1.setHourSuffix("H");
    assertFalse(df1.equals(df2));
    df2.setHourSuffix("H");
    assertTrue(df1.equals(df2));
    
    df1.setMinuteSuffix("M");
    assertFalse(df1.equals(df2));
    df2.setMinuteSuffix("M");
    assertTrue(df1.equals(df2));
    
    df1.setSecondSuffix("S");
    assertFalse(df1.equals(df2));
    df2.setSecondSuffix("S");
    assertTrue(df1.equals(df2));
    
    df1.setShowZeroDays(!df1.getShowZeroDays()); 
    assertFalse(df1.equals(df2));
    df2.setShowZeroDays(!df2.getShowZeroDays()); 
    assertTrue(df1.equals(df2));
    
    df1.setSecondFormatter(new DecimalFormat("0.0"));
    assertFalse(df1.equals(df2));
    df2.setSecondFormatter(new DecimalFormat("0.0"));
    assertTrue(df1.equals(df2));
}