Java Code Examples for org.jfree.chart.axis.DateAxis#setTickUnit()

The following examples show how to use org.jfree.chart.axis.DateAxis#setTickUnit() . 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: DateAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {

    DateAxis a1 = new DateAxis("Test");
    DateAxis a2 = new DateAxis("Test");
    assertTrue(a1.equals(a2));
    assertFalse(a1.equals(null));
    assertFalse(a1.equals("Some non-DateAxis object"));

    // tickUnit
    a1.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7));
    assertFalse(a1.equals(a2));
    a2.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7));
    assertTrue(a1.equals(a2));

    // dateFormatOverride
    a1.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    assertFalse(a1.equals(a2));
    a2.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    assertTrue(a1.equals(a2));

    // tickMarkPosition
    a1.setTickMarkPosition(DateTickMarkPosition.END);
    assertFalse(a1.equals(a2));
    a2.setTickMarkPosition(DateTickMarkPosition.END);
    assertTrue(a1.equals(a2));

    // timeline
    a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    assertFalse(a1.equals(a2));
    a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    assertTrue(a1.equals(a2));

}
 
Example 2
Source File: DateAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test to reproduce bug 2201869.
 */
public void testBug2201869() {
    TimeZone tz = TimeZone.getTimeZone("GMT");
    GregorianCalendar c = new GregorianCalendar(tz, Locale.UK);
    DateAxis axis = new DateAxis("Date", tz, Locale.UK);
    SimpleDateFormat sdf = new SimpleDateFormat("d-MMM-yyyy", Locale.UK);
    sdf.setCalendar(c);
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, sdf));
    Day d1 = new Day(1, 3, 2008);
    d1.peg(c);
    Day d2 = new Day(30, 6, 2008);
    d2.peg(c);
    axis.setRange(d1.getStart(), d2.getEnd());
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, 200, 100);
    axis.setTickMarkPosition(DateTickMarkPosition.END);
    List ticks = axis.refreshTicks(g2, new AxisState(), area,
            RectangleEdge.BOTTOM);
    assertEquals(3, ticks.size());
    DateTick t1 = (DateTick) ticks.get(0);
    assertEquals("31-Mar-2008", t1.getText());
    DateTick t2 = (DateTick) ticks.get(1);
    assertEquals("30-Apr-2008", t2.getText());
    DateTick t3 = (DateTick) ticks.get(2);
    assertEquals("31-May-2008", t3.getText());

    // now repeat for a vertical axis
    ticks = axis.refreshTicks(g2, new AxisState(), area,
            RectangleEdge.LEFT);
    assertEquals(3, ticks.size());
    t1 = (DateTick) ticks.get(0);
    assertEquals("31-Mar-2008", t1.getText());
    t2 = (DateTick) ticks.get(1);
    assertEquals("30-Apr-2008", t2.getText());
    t3 = (DateTick) ticks.get(2);
    assertEquals("31-May-2008", t3.getText());
}
 
Example 3
Source File: DateAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    DateAxis a1 = new DateAxis("Test");
    DateAxis a2 = new DateAxis("Test");
    assertTrue(a1.equals(a2));
    assertFalse(a1.equals(null));
    assertFalse(a1.equals("Some non-DateAxis object"));
    
    // tickUnit 
    a1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7));
    assertFalse(a1.equals(a2));
    a2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7));
    assertTrue(a1.equals(a2));

    // dateFormatOverride 
    a1.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    assertFalse(a1.equals(a2));
    a2.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    assertTrue(a1.equals(a2));

    // tickMarkPosition
    a1.setTickMarkPosition(DateTickMarkPosition.END);
    assertFalse(a1.equals(a2));
    a2.setTickMarkPosition(DateTickMarkPosition.END);
    assertTrue(a1.equals(a2));
    
    // timeline
    a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    assertFalse(a1.equals(a2));
    a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    assertTrue(a1.equals(a2));
    
}
 
Example 4
Source File: AnomalyGraphGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a chart containing the current/baseline data (in that order) as well as markers for
 * each anomaly interval. timeGranularity and windowMillis are used to determine the date format
 * and spacing for tick marks on the domain (x) axis.
 */
public JFreeChart createChart(final XYDataset dataset, final String metric,
    final TimeGranularity timeGranularity, final long windowMillis,
    final Map<MergedAnomalyResultDTO, String> anomaliesWithLabels) {

  // create the chart...
  final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // no chart title for email
                                                                    // image
      "Date (" + DEFAULT_TIME_ZONE.getID() + ")", // x axis label
      metric, // y axis label
      dataset, // data
      true, // include legend
      false, // tooltips - n/a if the chart will be saved as an img
      false // urls - n/a if the chart will be saved as an img
  );

  // get a reference to the plot for further customisation...
  final XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // dashboard webapp currently uses solid blue for current and dashed blue for baseline
  // (5/2/2016)
  final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setSeriesShapesVisible(0, false);
  renderer.setSeriesShapesVisible(1, false);
  renderer.setSeriesPaint(0, Color.BLUE);
  renderer.setSeriesPaint(1, Color.BLUE);
  // http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
  // set baseline to be dashed
  renderer.setSeriesStroke(1,
      new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {
          2.0f, 6.0f
      }, 0.0f));
  plot.setRenderer(renderer);

  DateAxis axis = (DateAxis) plot.getDomainAxis();
  DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
  SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
  axis.setDateFormatOverride(dateFormat);
  axis.setTickUnit(dateTickUnit);
  axis.setVerticalTickLabels(true);

  List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
  for (Marker marker : anomalyIntervals) {
    plot.addDomainMarker(marker);
  }

  return chart;

}