List of usage examples for org.jfree.chart.axis DateAxis getMinimumDate
public Date getMinimumDate()
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * configure domainAxis (label, timeZone, locale, tick labels) * of time-series chart//from w ww .j a v a 2s . co m * @param dateAxis */ private void configureDomainAxis(DateAxis dateAxis) { if (this.begin != null) dateAxis.setMinimumDate(this.begin); if (this.end != null) dateAxis.setMaximumDate(this.end); dateAxis.setTimeZone(this.timeZone); Date dateMin = dateAxis.getMinimumDate(); Date dateMax = dateAxis.getMaximumDate(); //DateFormat formatter = new SimpleDateFormat("d.MM.yyyy HH:mm:ss.SSS");; DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale); String label = "Time: " + formatter.format(dateMin) + " .. " + formatter.format(dateMax); formatter = new SimpleDateFormat("z"); label += " " + formatter.format(dateMax); dateAxis.setLabel(label); TimeInstant max = new TimeInstant(dateMax); TimeInstant min = new TimeInstant(dateMin); TimeSpan diff = TimeOperations.diff(max, min); if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.DAYS))) formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.HOURS))) formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale); else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.MINUTES))) formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); else formatter = new SimpleDateFormat("HH:mm:ss.SSS"); dateAxis.setDateFormatOverride(formatter); dateAxis.setVerticalTickLabels(true); }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
private void addDomainGridLinesToPlot(int hourInterval, XYPlot plot) { DateAxis axis = (DateAxis) plot.getDomainAxis(); Calendar currDate = Calendar.getInstance(); currDate.setTime(axis.getMinimumDate()); Calendar maxDate = Calendar.getInstance(); maxDate.setTime(axis.getMaximumDate()); // we do not paint the first domain grid lines since it conflicts with // the axis line boolean first = true; while (currDate.compareTo(maxDate) < 0) { if (first) { first = false;//w w w .ja v a2 s . co m } else { paintDomainGridLine(currDate, plot); } currDate.add(Calendar.HOUR, hourInterval); } }
From source file:com.zimbra.perf.chart.ChartUtil.java
/** * Updates axes for all charts so that they display the same time interval. */// w w w. ja v a 2s .c om private void lineUpAxes() { for (JFreeChart chart : mCharts) { XYPlot plot = (XYPlot) chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); Date chartMinDate = axis.getMinimumDate(); Date chartMaxDate = axis.getMaximumDate(); if (chartMinDate != null && mMinDate < chartMinDate.getTime()) { axis.setMinimumDate(new Date(mMinDate)); } if (chartMaxDate != null && mMaxDate > chartMaxDate.getTime()) { axis.setMaximumDate(new Date(mMaxDate)); } } }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initAxis() { DateAxis domainAxis = (DateAxis) getPlot().getDomainAxis(); // configure the Date Axis (if startTime & endTime is set) if (this.chartDefinition.getStartTime() != null && this.chartDefinition.getEndTime() != null && !this.chartDefinition.getStartTime().equals(this.chartDefinition.getEndTime())) { // creat the SegmentedTimeline long startTime = this.chartDefinition.getStartTime().getTime(); long endTime = this.chartDefinition.getEndTime().getTime(); if (endTime == -3600000) { // adjust 00:00 endTime += 86400000;// w ww.j a v a 2 s. c om } long segmentSize = 60 * 1000; // minute int segmentsIncluded = (int) (endTime - startTime) / (60 * 1000); int segmentsExcluded = 24 * 60 - segmentsIncluded; SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded); Date fromDate = domainAxis.getMinimumDate(); Date toDate = domainAxis.getMaximumDate(); long fromTime = fromDate.getTime(); long toTime = toDate.getTime(); // get year/month/day from fromTime and hour/minute from diagrm.startTime Date truncatedDate = DateUtils.truncate(fromDate, Calendar.DAY_OF_MONTH); Calendar truncatedCalendar = DateUtils.toCalendar(truncatedDate); Calendar startCalendar = DateUtils.toCalendar(this.chartDefinition.getStartTime()); truncatedCalendar.set(Calendar.HOUR_OF_DAY, startCalendar.get(Calendar.HOUR_OF_DAY)); truncatedCalendar.set(Calendar.MINUTE, startCalendar.get(Calendar.MINUTE)); timeline.setStartTime(truncatedCalendar.getTimeInMillis()); timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); timeline.addBaseTimelineExclusions(fromTime, toTime); timeline.setAdjustForDaylightSaving(true); domainAxis.setTimeline(timeline); } // make sure the markers are within the rangeAxis ValueAxis rangeAxis = getPlot().getRangeAxis(); for (Marker marker : this.markers.values()) { if (marker instanceof ValueMarker) { ValueMarker valueMarker = (ValueMarker) marker; if (marker.getAlpha() > 0 && valueMarker.getValue() != 0.0) { if (valueMarker.getValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } if (valueMarker.getValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } } } else { IntervalMarker intervalMarker = (IntervalMarker) marker; if (marker.getAlpha() > 0 && intervalMarker.getStartValue() != 0.0) { if (intervalMarker.getStartValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(intervalMarker.getStartValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } if (intervalMarker.getEndValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(intervalMarker.getEndValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } } } } }
From source file:org.cds06.speleograph.graph.DateAxisEditor.java
public DateAxisEditor(DateAxis dateAxis) { super(SpeleoGraphApp.getInstance(), true); this.axis = dateAxis; this.setTitle(I18nSupport.translate("graph.dateAxisEditor")); JPanel panel = new JPanel(); panel.setLayout(//from w w w .j av a 2 s . c o m new FormLayout("r:p,4dlu,p:grow,4dlu", "p:grow,p,4dlu:grow,p,4dlu:grow,p,4dlu:grow,p,p:grow")); CellConstraints cc = new CellConstraints(); panel.add(new JLabel("Format :"), cc.xy(1, 2)); panel.add(dateSelector, cc.xy(3, 2)); panel.add(new JLabel("Date dbut :"), cc.xy(1, 4)); panel.add(minDate, cc.xy(3, 4)); panel.add(new JLabel("Date fin :"), cc.xy(1, 6)); panel.add(maxDate, cc.xy(3, 6)); ButtonBarBuilder barBuilder = new ButtonBarBuilder(); barBuilder.addGlue(); //Cancel button barBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("cancel")); } @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); //Ok button barBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("ok")); } @Override public void actionPerformed(ActionEvent e) { axis.setDateFormatOverride((DateFormat) dateSelector.getSelectedItem()); axis.setMinimumDate(minDate.getDate()); axis.setMaximumDate(maxDate.getDate()); setVisible(false); } }); panel.add(barBuilder.build(), cc.xyw(1, 8, 3)); minDate.setDate(dateAxis.getMinimumDate()); maxDate.setDate(dateAxis.getMaximumDate()); if (dateAxis.getDateFormatOverride() != null && dateAxis.getDateFormatOverride() instanceof HumanSimpleDateFormat) { dateSelector.setSelectedItem(dateAxis.getDateFormatOverride()); } setContentPane(panel); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setSize(panel.getPreferredSize().width + 100, panel.getPreferredSize().height + 100); }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * some jFreeChart Axis settings for TimeValueDiagram * @param plot jFreeChart plot instance * @param rangeAxisLabel Label of rangeAxis *//*from ww w . j a va 2 s .c o m*/ private void buildTimeValueDiagramAxisFormat(XYPlot plot, String rangeAxisLabel) { System.out.println("StatisticGrafic.buildTimeValueDiagramAxisFormat"); ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis(); double a = 0.1 * Math.max(Math.abs(statistic.getValueLow()), Math.abs(statistic.getValueHigh())); rangeAxis.setLowerBound(statistic.getValueLow() - a); rangeAxis.setUpperBound(statistic.getValueHigh() + a); rangeAxis.setLabel(rangeAxisLabel); rangeAxis.setLabelFont(FONT_DEFAULT); DateAxis dateAxis = new DateAxis(); DateAxis[] domainAxisArray = new DateAxis[1]; domainAxisArray[0] = dateAxis; plot.setDomainAxes(domainAxisArray); dateAxis.setLowerBound(statistic.getTimeLow()); dateAxis.setUpperBound(statistic.getTimeHigh()); long diff = statistic.getTimeHigh() - statistic.getTimeLow(); String format, unit; if (diff > 24 * 60 * 60 * 1000) { format = "d.MM.yyyy"; unit = "[day]"; } else if (diff > 60 * 60 * 1000) { format = "H:mm"; unit = "[h]"; } else if (diff > 60 * 1000) { format = "m:ss"; unit = "[min]"; } else if (diff > 1000) { format = "s.S"; unit = "[sec]"; } else { format = "S"; unit = "[millisec]"; } SimpleDateFormat sdf = new SimpleDateFormat(format); dateAxis.setDateFormatOverride(sdf); SimpleDateFormat sdf1 = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS"); String von = sdf1.format(dateAxis.getMinimumDate()); String bis = sdf1.format(dateAxis.getMaximumDate()); dateAxis.setLabel(von + " Time " + unit + " " + bis); dateAxis.setLabelFont(FONT_DEFAULT); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java
/** * Initializes the graph. This method generates the backing {@link JFreeChart} from the time series and graph * parameter data./*from w w w . j av a 2 s . co m*/ * * @throws GraphException if the initialization fails */ public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE); Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR); boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP); Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, DEFAULT_GRAPH_STROKE); Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); checkSeriesType(data); @SuppressWarnings("unchecked") List<? extends TimeSeriesInterface> timeData = (List<? extends TimeSeriesInterface>) data; TimeSeriesCollection dataset = new TimeSeriesCollection(); int seriesCount = 1; for (TimeSeriesInterface series : timeData) { dataset.addSeries(buildTimeSeries(series, seriesCount)); seriesCount += 1; } // actually create the chart this.chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, false, graphToolTip, false); // start customizing it Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor); Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); this.chart.setBackgroundPaint(backgroundColor); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setRangeGridlinePaint(graphRangeGridlinePaint); if (graphBorder) { } else { plot.setOutlinePaint(null); } //Use a TextTitle to change the font of the graph title TextTitle title1 = new TextTitle(); title1.setText(title); title1.setFont(titleFont); chart.setTitle(title1); //Makes a wrapper for the legend to remove the border around it if (legend) { LegendTitle legend1 = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legend1.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend1.setWrapper(wrapper); legend1.setPosition(RectangleEdge.BOTTOM); legend1.setHorizontalAlignment(HorizontalAlignment.CENTER); if (params.get(GraphSource.LEGEND_FONT) instanceof Font) { legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT))); } chart.addSubtitle(legend1); } boolean include0 = getParam(GraphSource.GRAPH_RANGE_INCLUDE_0, Boolean.class, true); NumberAxis numAxis = (NumberAxis) plot.getRangeAxis(); double rangeLower = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, numAxis.getLowerBound()); double rangeUpper = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, numAxis.getUpperBound()); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (include0) { rangeLower = 0; } numAxis.setRange(rangeLower, rangeUpper); if (graphRangeIntegerTick) { numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); setupFont(numAxis, GraphSource.GRAPH_Y_AXIS_FONT); if (params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT) instanceof Font) { numAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT))); } TimeResolution minimumResolution = getMinimumResolution(timeData); DateFormat dateFormat = getParam(GraphSource.GRAPH_DATE_FORMATTER, DateFormat.class, new DefaultDateFormatFactory().getFormat(minimumResolution)); if (params.get(DATE_AXIS) instanceof DateAxis) { DateAxis dateAxis = (DateAxis) params.get(DATE_AXIS); dateAxis.setLabel(xLabel); plot.setDomainAxis(dateAxis); } DateAxis dateAxis = ((DateAxis) plot.getDomainAxis()); dateAxis.setDateFormatOverride(dateFormat); if (params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT) instanceof Font) { dateAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT))); } int minTick = getParam(GraphSource.GRAPH_MIN_DOMAIN_TICK, Integer.class, 1); if (minTick <= 0) { minTick = 1; } dateAxis.setTickUnit(getDateTickUnit(minimumResolution, minTick), false, false); //dateAxis.setMinorTickMarksVisible(true); //dateAxis.setMinorTickCount(7); dateAxis.setMinorTickMarkOutsideLength(2); Integer minorTick = getParam(GraphSource.GRAPH_MINOR_TICKS, Integer.class, null); if (minorTick != null) { int minorVal = minorTick; if (minorVal > 0) { dateAxis.setMinorTickCount(minorVal); } } setupFont(dateAxis, GraphSource.GRAPH_X_AXIS_FONT); //double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN); double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN); dateAxis.setLowerMargin(lowerMargin); //double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN); double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN); dateAxis.setUpperMargin(upperMargin); Date domainLower = getParam(GraphSource.GRAPH_DOMAIN_LOWER_BOUND, Date.class, dateAxis.getMinimumDate()); Date domainUpper = getParam(GraphSource.GRAPH_DOMAIN_UPPER_BOUND, Date.class, dateAxis.getMaximumDate()); dateAxis.setRange(domainLower, domainUpper); // depending on the domain axis range, display either 1 tick per day, week, month or year TickUnits standardUnits = new TickUnits(); standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1)); standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7)); standardUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1)); standardUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1)); dateAxis.setStandardTickUnits(standardUnits); TimeSeriesRenderer renderer = new TimeSeriesRenderer(dataset); setupRenderer(renderer, graphColor, graphShape, graphStroke); renderer.setBaseFillPaint(Color.BLACK); renderer.setSeriesOutlinePaint(0, Color.WHITE); //renderer.setUseOutlinePaint(true); plot.setRenderer(renderer); this.initialized = true; }