List of usage examples for org.jfree.data.time Day getMiddleMillisecond
public long getMiddleMillisecond()
From source file:org.jfree.chart.demo.EventFrequencyDemo1.java
private static CategoryDataset createDataset() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); Day day = new Day(12, 6, 2002); Day day1 = new Day(14, 6, 2002); Day day2 = new Day(15, 6, 2002); Day day3 = new Day(10, 7, 2002); Day day4 = new Day(20, 7, 2002); Day day5 = new Day(22, 8, 2002); defaultcategorydataset.setValue(new Long(day.getMiddleMillisecond()), "Series 1", "Requirement 1"); defaultcategorydataset.setValue(new Long(day.getMiddleMillisecond()), "Series 1", "Requirement 2"); defaultcategorydataset.setValue(new Long(day1.getMiddleMillisecond()), "Series 1", "Requirement 3"); defaultcategorydataset.setValue(new Long(day2.getMiddleMillisecond()), "Series 2", "Requirement 1"); defaultcategorydataset.setValue(new Long(day3.getMiddleMillisecond()), "Series 2", "Requirement 3"); defaultcategorydataset.setValue(new Long(day4.getMiddleMillisecond()), "Series 3", "Requirement 2"); defaultcategorydataset.setValue(new Long(day5.getMiddleMillisecond()), "Series 1", "Requirement 4"); return defaultcategorydataset; }
From source file:org.jfree.chart.demo.EventFrequencyDemo.java
/** * Creates a new demo./*from ww w .j ava 2 s.co m*/ * * @param title the frame title. */ public EventFrequencyDemo(final String title) { super(title); // create a dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // initialise the data... final Day d1 = new Day(12, SerialDate.JUNE, 2002); final Day d2 = new Day(14, SerialDate.JUNE, 2002); final Day d3 = new Day(15, SerialDate.JUNE, 2002); final Day d4 = new Day(10, SerialDate.JULY, 2002); final Day d5 = new Day(20, SerialDate.JULY, 2002); final Day d6 = new Day(22, SerialDate.AUGUST, 2002); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 1"); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 2"); dataset.setValue(new Long(d2.getMiddleMillisecond()), "Series 1", "Requirement 3"); dataset.setValue(new Long(d3.getMiddleMillisecond()), "Series 2", "Requirement 1"); dataset.setValue(new Long(d4.getMiddleMillisecond()), "Series 2", "Requirement 3"); dataset.setValue(new Long(d5.getMiddleMillisecond()), "Series 3", "Requirement 2"); dataset.setValue(new Long(d6.getMiddleMillisecond()), "Series 1", "Requirement 4"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Event Frequency Demo", // title "Category", // domain axis label "Value", // range axis label dataset, // dataset PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips false // URLs ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC)); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f); plot.setRangeAxis(new DateAxis("Date")); final CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); // final CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); // renderer.setToolTipGenerator(toolTipGenerator); // plot.setRenderer(renderer); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Test the getSurroundingItems() method to ensure it is returning the * values we expect.// w ww .j ava 2 s . c o m */ @Test public void testGetSurroundingItems() { TimeSeries series = new TimeSeries("Series 1"); TimeSeriesCollection collection = new TimeSeriesCollection(series); collection.setXPosition(TimePeriodAnchor.MIDDLE); // for a series with no data, we expect {-1, -1}... int[] result = collection.getSurroundingItems(0, 1000L); assertTrue(result[0] == -1); assertTrue(result[1] == -1); // now test with a single value in the series... Day today = new Day(); long start1 = today.getFirstMillisecond(); long middle1 = today.getMiddleMillisecond(); long end1 = today.getLastMillisecond(); series.add(today, 99.9); result = collection.getSurroundingItems(0, start1); assertTrue(result[0] == -1); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, middle1); assertTrue(result[0] == 0); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, end1); assertTrue(result[0] == 0); assertTrue(result[1] == -1); // now add a second value to the series... Day tomorrow = (Day) today.next(); long start2 = tomorrow.getFirstMillisecond(); long middle2 = tomorrow.getMiddleMillisecond(); long end2 = tomorrow.getLastMillisecond(); series.add(tomorrow, 199.9); result = collection.getSurroundingItems(0, start2); assertTrue(result[0] == 0); assertTrue(result[1] == 1); result = collection.getSurroundingItems(0, middle2); assertTrue(result[0] == 1); assertTrue(result[1] == 1); result = collection.getSurroundingItems(0, end2); assertTrue(result[0] == 1); assertTrue(result[1] == -1); // now add a third value to the series... Day yesterday = (Day) today.previous(); long start3 = yesterday.getFirstMillisecond(); long middle3 = yesterday.getMiddleMillisecond(); long end3 = yesterday.getLastMillisecond(); series.add(yesterday, 1.23); result = collection.getSurroundingItems(0, start3); assertTrue(result[0] == -1); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, middle3); assertTrue(result[0] == 0); assertTrue(result[1] == 0); result = collection.getSurroundingItems(0, end3); assertTrue(result[0] == 0); assertTrue(result[1] == 1); }
From source file:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.java
/** * Creates a sample dataset./* w w w.ja v a2 s .c o m*/ * * @return A sample dataset. */ protected CategoryDataset createDataset(boolean isDemo) { if (isDemo) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // initialise the data... Day d1 = new Day(12, MonthConstants.JUNE, 2002); Day d2 = new Day(14, MonthConstants.JUNE, 2002); Day d3 = new Day(15, MonthConstants.JUNE, 2002); Day d4 = new Day(10, MonthConstants.JULY, 2002); Day d5 = new Day(20, MonthConstants.JULY, 2002); Day d6 = new Day(22, MonthConstants.AUGUST, 2002); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 1"); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 2"); dataset.setValue(new Long(d2.getMiddleMillisecond()), "Series 1", "Requirement 3"); dataset.setValue(new Long(d3.getMiddleMillisecond()), "Series 2", "Requirement 1"); dataset.setValue(new Long(d4.getMiddleMillisecond()), "Series 2", "Requirement 3"); dataset.setValue(new Long(d5.getMiddleMillisecond()), "Series 3", "Requirement 2"); dataset.setValue(new Long(d6.getMiddleMillisecond()), "Series 1", "Requirement 4"); return dataset; } else { setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; String[][] y = new String[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) y[i][index] = depValues[i][index]; // create the dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //dependent for (int j = 0; j < xyLength; j++) for (int i = 0; i < independentVarLength; i++) { //System.out.println("*"+x[j][i]+"*"); if (x[j][i] != null && !x[j][i].equals("NaN") && x[j][i].length() != 0 && y[j][0] != null) { Day day = DateParser.parseDay(x[j][i]); dataset.addValue(new Long(day.getMiddleMillisecond()), y[j][0], independentHeaders[i]); } } return dataset; } }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private CategoryDataset createCategoryDataset_Time(String time_type) { String[][] x = new String[xyLength][no_category]; String[][] y = new String[xyLength][1]; for (int index = 0; index < no_category; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < 1; index++) for (int i = 0; i < xyLength; i++) y[i][index] = depValues[i][index]; // create the dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //dependent/*w ww . j a v a 2s . c om*/ for (int j = 0; j < xyLength; j++) for (int i = 0; i < no_category; i++) { if (x[j][i] != "NaN") { if (time_type.equalsIgnoreCase("Day")) { Day time = DateParser.parseDay(x[j][i]); dataset.addValue(new Long(time.getMiddleMillisecond()), y[j][0], independentHeaders[i]); } else if (time_type.equalsIgnoreCase("Month")) { Month time = DateParser.parseMonth(x[j][i]); dataset.addValue(new Long(time.getMiddleMillisecond()), y[j][0], independentHeaders[i]); } else if (time_type.equalsIgnoreCase("Minute")) { Minute time = DateParser.parseMinute(x[j][i]); dataset.addValue(new Long(time.getMiddleMillisecond()), y[j][0], independentHeaders[i]); } } } return dataset; }