List of usage examples for org.jfree.chart.axis DateTickUnitType YEAR
DateTickUnitType YEAR
To view the source code for org.jfree.chart.axis DateTickUnitType YEAR.
Click Source Link
From source file:org.sunzoft.sunstock.StockMain.java
protected JFreeChart createChart() { // 2Chart[??] XYDataset dataset = initChartData(); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset); XYPlot xyplot = (XYPlot) chart.getPlot(); //addIndexChart(xyplot); ChartUtils.setAntiAlias(chart);// ChartUtils.setTimeSeriesStyle(xyplot, false, true); ChartUtils.setLegendEmptyBorder(chart); // X??/*from ww w. j a va 2 s . c o m*/ DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis(); domainAxis.setAutoTickUnitSelection(false); domainAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); DateTickUnit dateTickUnit; if (dataset.getItemCount(0) < 30) dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 5, new SimpleDateFormat("yyyy-MM-dd")); // ?? else if (dataset.getItemCount(0) < 100) dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 10, new SimpleDateFormat("yyyy-MM-dd")); // ?? else if (dataset.getItemCount(0) < 200) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("yyyy/MM")); // ?? else if (dataset.getItemCount(0) < 500) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 3, new SimpleDateFormat("yyyy/MM")); // ?? else if (dataset.getItemCount(0) < 1000) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 6, new SimpleDateFormat("yyyy/MM")); // ?? else dateTickUnit = new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat("yyyy")); // ?? // ?? domainAxis.setTickUnit(dateTickUnit); return chart; }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java
private TickUnits getUnits(CalendarFieldSplitPeriod period) { int field = period.getField(); boolean good_match = false; for (DateTickUnitType unit : new DateTickUnitType[] { DateTickUnitType.SECOND, DateTickUnitType.MINUTE, DateTickUnitType.HOUR, DateTickUnitType.DAY, DateTickUnitType.MONTH, DateTickUnitType.YEAR }) { if (field == unit.getCalendarField()) { TickUnits units = new TickUnits(); int count = period.getCount(); int nsplit = period.getNsplit(); if (count == 1 && nsplit == 1) { return null; // let jfree work it out. }// w w w . j av a2s.c o m if (nsplit > 50) { return null; // period unit is too small } // include all multiples that are exact factors of count for (int i = 1; i <= count; i++) { if (count % i == 0) { units.add(new DateTickUnit(unit, i)); if (i > 1 && (count / i) < 8) { good_match = true; } } } // now larger multiples of count that factor nsplit for (int i = 2; i < nsplit && i < 50; i++) { if (nsplit % i == 0) { units.add(new DateTickUnit(unit, i * count)); if (i > 1 && (nsplit / i) < 8) { good_match = true; } } } if (good_match) { return units; } return null; } } return null; }
From source file:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java
private static TickUnitSource createStandardDateTickUnits() { TickUnits tickunits = new TickUnits(); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy"); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.YEAR, 1, simpledateformat)); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, DateTickUnitType.YEAR, 1, simpledateformat)); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, DateTickUnitType.YEAR, 5, simpledateformat)); return tickunits; }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
private static TickUnitSource createStandardDateTickUnits() { TickUnits units = new TickUnits(); DateFormat df = new SimpleDateFormat("yyyy"); units.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.YEAR, 1, df)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 2, DateTickUnitType.YEAR, 1, df)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 5, DateTickUnitType.YEAR, 5, df)); return units; }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java
private TickUnits getUnits() { TickUnits units = new TickUnits(); units.add(new DateTickUnit(DateTickUnitType.SECOND, 1)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 1)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 10)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 15)); units.add(new DateTickUnit(DateTickUnitType.HOUR, 1)); units.add(new DateTickUnit(DateTickUnitType.HOUR, 12)); units.add(new DateTickUnit(DateTickUnitType.DAY, 1)); units.add(new DateTickUnit(DateTickUnitType.DAY, 7)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 1)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 3)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 6)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 1)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 10)); return units; }
From source file:OAT.ui.util.UiUtil.java
public static TickUnits createSimpleTimeTickUnits() { TickUnits tickUnits = new TickUnits(); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); SimpleDateFormat weekDayFormatter = new SimpleDateFormat("EEE"); SimpleDateFormat dayFormatter = new SimpleDateFormat("dd-mm"); SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM-yy"); SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy"); //tickUnits.add(new DateTickUnit(DateTickUnitType.MINUTE, 30, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 1, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 2, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 4, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 6, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 12, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1, DateTickUnitType.HOUR, 1, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 2, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 15, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1, DateTickUnitType.DAY, 1, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 3, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 6, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.MONTH, 1, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 10, yearFormatter)); return tickUnits; }
From source file:sk.uniza.fri.pds.spotreba.energie.gui.MainGui.java
private void showSpendingStatisticsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSpendingStatisticsActionPerformed final SpendingStatisticsParameters params = new SpendingStatisticsParameters(); int option = showUniversalInputDialog(params, "Vvoj spotreby"); if (option == JOptionPane.OK_OPTION) { new SwingWorker<List, RuntimeException>() { @Override//from w ww . j ava2 s . c om protected List doInBackground() throws Exception { try { return SeHistoriaService.getInstance().getSpendingStatistics(params); } catch (RuntimeException e) { publish(e); return null; } } @Override protected void done() { try { List<KrokSpotreby> spendingStatistics = get(); if (spendingStatistics != null) { final TimeSeries series = new TimeSeries(""); final String title = "Vvoj spotreby"; for (KrokSpotreby krok : spendingStatistics) { series.add(new Month(krok.getDatumOd()), krok.getSpotreba()); } final IntervalXYDataset dataset = (IntervalXYDataset) new TimeSeriesCollection(series); JFreeChart chart = ChartFactory.createXYBarChart(title, // title "", // x-axis label true, // date axis? "", // y-axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // create legend? true, // generate tooltips? false // generate URLs? ); // Set date axis style DateAxis axis = (DateAxis) ((XYPlot) chart.getPlot()).getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy")); DateFormat formatter = new SimpleDateFormat("yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnitType.YEAR, 1, formatter); axis.setTickUnit(unit); JOptionPane.showMessageDialog(null, new ChartPanel(chart)); } } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } @Override protected void process(List<RuntimeException> chunks) { if (chunks.size() > 0) { showException("Chyba", chunks.get(0)); } } }.execute(); } }
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 a v a 2 s . c o 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; }
From source file:com.freedomotic.jfrontend.extras.GraphPanel.java
private void createChart(UsageDataFrame points, String title) { series = new TimeSeries(title); for (UsageData d : points.getData()) { Date resultdate = d.getDateTime(); Millisecond ms_read = new Millisecond(resultdate); int poweredValue = -1; if (d.getObjBehavior().equalsIgnoreCase("powered")) { poweredValue = d.getObjValue().equalsIgnoreCase("true") ? 1 : 0; } else if (d.getObjBehavior().equalsIgnoreCase("brigthness")) { try { poweredValue = Integer.parseInt(d.getObjValue()); } catch (NumberFormatException ex) { poweredValue = -1;//from w w w . j ava 2 s . co m } } series.addOrUpdate(ms_read, poweredValue); } XYDataset xyDataset = new TimeSeriesCollection(series); chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALUE", xyDataset, true, // legend true, // tooltips false // urls ); chart.setAntiAlias(true); // Set plot styles XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); // Set series line styles plot.setRenderer(new XYStepRenderer()); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setShapesVisible(true); renderer.setShapesFilled(true); } // Set date axis style DateAxis axis = (DateAxis) plot.getDomainAxis(); String formatString = "MM-dd HH"; DateTickUnitType dtut = DateTickUnitType.HOUR; if (jComboGranularity.getSelectedItem().equals("Year")) { formatString = "yyyy"; dtut = DateTickUnitType.YEAR; } else if (jComboGranularity.getSelectedItem().equals("Month")) { axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM")); dtut = DateTickUnitType.MONTH; } else if (jComboGranularity.getSelectedItem().equals("Day")) { axis.setDateFormatOverride(new SimpleDateFormat("MM-dd")); dtut = DateTickUnitType.DAY; } else if (jComboGranularity.getSelectedItem().equals("Minute")) { formatString = "MM-dd HH:mm"; dtut = DateTickUnitType.MINUTE; } else if (jComboGranularity.getSelectedItem().equals("Second")) { formatString = "HH:mm:SS"; dtut = DateTickUnitType.SECOND; } DateFormat formatter = new SimpleDateFormat(formatString); DateTickUnit unit = new DateTickUnit(dtut, 1, formatter); axis.setTickUnit(unit); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); graphPanel.removeAll(); graphPanel.add(chartPanel); }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * Sets all the axis formatting options. This includes the colors and fonts to use on * the axis as well as the color to use when drawing the axis line. * * @param axis the axis to format//from w w w . j a v a 2s .co m * @param labelFont the font to use for the axis label * @param labelColor the color of the axis label * @param tickLabelFont the font to use for each tick mark value label * @param tickLabelColor the color of each tick mark value label * @param tickLabelMask formatting mask for the label. If the axis is a NumberAxis then * the mask should be <code>java.text.DecimalFormat</code> mask, and * if it is a DateAxis then the mask should be a * <code>java.text.SimpleDateFormat</code> mask. * @param verticalTickLabels flag to draw tick labels at 90 degrees * @param lineColor color to use when drawing the axis line and any tick marks */ protected void configureAxis(Axis axis, JRFont labelFont, Color labelColor, JRFont tickLabelFont, Color tickLabelColor, String tickLabelMask, Boolean verticalTickLabels, Paint lineColor, AxisSettings axisSettings, Comparable<?> axisMinValue, Comparable<?> axisMaxValue) throws JRException { configureAxis(axis, labelFont, labelColor, tickLabelFont, tickLabelColor, tickLabelMask, verticalTickLabels, lineColor, axisSettings, DateTickUnitType.YEAR, axisMinValue, axisMaxValue); }