List of usage examples for org.jfree.chart.axis DateAxis setDateFormatOverride
public void setDateFormatOverride(DateFormat formatter)
From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java
/** * Set the axes in the chart model.//from w ww . j a v a 2 s. co m * * @param plotType The target plot type. * @param chartModel The target chart model. * @throws MacroExecutionException if the axes are incorrectly configured. */ public void setAxes(PlotType plotType, SimpleChartModel chartModel) throws MacroExecutionException { AxisType[] defaultAxisTypes = plotType.getDefaultAxisTypes(); for (int i = 0; i < axisTypes.length; i++) { AxisType type = axisTypes[i]; if (i >= defaultAxisTypes.length) { if (type != null) { throw new MacroExecutionException("To many axes for plot type."); } continue; } if (type == null) { type = defaultAxisTypes[i]; } Axis axis; switch (type) { case NUMBER: NumberAxis numberAxis = new NumberAxis(); axis = numberAxis; setNumberLimits(numberAxis, i); break; case CATEGORY: axis = new CategoryAxis(); break; case DATE: DateAxis dateAxis = new DateAxis(); axis = dateAxis; dateAxis.setTickMarkPosition(DateTickMarkPosition.END); if (axisDateFormat[i] != null) { try { DateFormat dateFormat = new SimpleDateFormat(axisDateFormat[i], localeConfiguration.getLocale()); dateAxis.setDateFormatOverride(dateFormat); } catch (IllegalArgumentException e) { throw new MacroExecutionException( String.format("Invalid date format [%s].", axisDateFormat[i])); } } setDateLimits(dateAxis, i); break; default: throw new MacroExecutionException(String.format("Unsupported axis type [%s]", type.getName())); } chartModel.setAxis(i, axis); } }
From source file:com.charts.ThreeMonthChart.java
public ThreeMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/*from w w w .j a v a2s . co m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.SixMonthChart.java
public SixMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from ww w .ja v a2 s .com rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method createChart./* ww w . ja v a 2s .c o m*/ * * @param strategyData * StrategyData * @param title * String * @return JFreeChart */ private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) { DateAxis dateAxis = new DateAxis("Date"); dateAxis.setVerticalTickLabels(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm")); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); NumberAxis priceAxis = new NumberAxis("Price"); priceAxis.setAutoRange(true); priceAxis.setAutoRangeIncludesZero(false); XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis, strategyData.getCandleDataset().getRenderer()); pricePlot.setOrientation(PlotOrientation.VERTICAL); pricePlot.setDomainPannable(true); pricePlot.setRangePannable(true); pricePlot.setDomainCrosshairVisible(true); pricePlot.setDomainCrosshairLockedOnData(true); pricePlot.setRangeCrosshairVisible(true); pricePlot.setRangeCrosshairLockedOnData(true); pricePlot.setRangeGridlinePaint(new Color(204, 204, 204)); pricePlot.setDomainGridlinePaint(new Color(204, 204, 204)); pricePlot.setBackgroundPaint(Color.white); /* * Calculate the number of 15min segments in this trading day. i.e. * 6.5hrs/15min = 26 and there are a total of 96 = one day */ int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime()) / (1000 * 60 * 15); SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, segments15min, (96 - segments15min)); Date startDate = tradingday.getOpen(); Date endDate = tradingday.getClose(); if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) { startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod() .getStart(); startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate); endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0) .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod() .getStart(); endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate); } segmentedTimeline.setStartTime(startDate.getTime()); segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(), tradingday.getClose(), segmentedTimeline)); dateAxis.setTimeline(segmentedTimeline); // Build Combined Plot CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis); mainPlot.add(pricePlot, 4); int axixIndex = 0; int datasetIndex = 0; /* * Change the List of indicators so that the candle dataset is the first * one in the list. The main chart must be plotted first. */ List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0); for (IndicatorDataset item : strategyData.getIndicators()) { if (IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (IndicatorDataset item : strategyData.getIndicators()) { if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (int i = 0; i < indicators.size(); i++) { IndicatorDataset indicator = indicators.get(i); if (indicator.getDisplaySeries(0)) { if (indicator.getSubChart(0)) { String axisName = "Price"; if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol(); } else { org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries .newInstance(indicator.getType(0)); axisName = code.getDisplayName(); } NumberAxis subPlotAxis = new NumberAxis(axisName); subPlotAxis.setAutoRange(true); subPlotAxis.setAutoRangeIncludesZero(false); XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis, indicator.getRenderer()); subPlot.setOrientation(PlotOrientation.VERTICAL); subPlot.setDomainPannable(true); subPlot.setRangePannable(true); subPlot.setDomainCrosshairVisible(true); subPlot.setDomainCrosshairLockedOnData(true); subPlot.setRangeCrosshairVisible(true); subPlot.setRangeCrosshairLockedOnData(true); subPlot.setRangeGridlinePaint(new Color(204, 204, 204)); subPlot.setDomainGridlinePaint(new Color(204, 204, 204)); subPlot.setBackgroundPaint(Color.white); XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } mainPlot.add(subPlot, 1); } else { datasetIndex++; pricePlot.setDataset(datasetIndex, (XYDataset) indicator); if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { // add secondary axis axixIndex++; final NumberAxis axis2 = new NumberAxis( ((CandleSeries) indicator.getSeries(0)).getSymbol()); axis2.setAutoRange(true); axis2.setAutoRangeIncludesZero(false); pricePlot.setRangeAxis(datasetIndex, axis2); pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT); pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex); pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer()); } else { pricePlot.setRenderer(datasetIndex, indicator.getRenderer()); } XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } } } } JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true); jfreechart.setAntiAlias(false); return jfreechart; }
From source file:com.charts.OneMonthChart.java
public OneMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);// www . j a v a2 s . c o m rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYStepChart(XYDataset dataset) { DateAxis xAxis = new DateAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }/*from w ww.j a va 2 s . c o m*/ XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(orientation); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart("XYStep Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:de.xirp.ui.widgets.panels.LiveChartComposite.java
/** * Initializes the listeners./*from w ww . ja v a 2 s. co m*/ */ private void init() { addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { pool.removeDatapoolReceiveListener(listener); } }); initDatapool(); keysList = ProfileManager.getSensorDatapoolKeys(robotName); dataset = new TimeSeriesCollection(); chart = createChart(dataset); SWTUtil.setGridLayout(this, 1, true); final XToolBar toolBar = new XToolBar(this, SWT.FLAT); SWTUtil.setGridData(toolBar, true, false, SWT.FILL, SWT.BEGINNING, 1, 1); keysMenu = new Menu(getShell(), SWT.POP_UP); keys = new XToolItem(toolBar, SWT.DROP_DOWN | SWT.FLAT); keys.setImage(ImageManager.getSystemImage(SystemImage.ADD)); keys.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.startOrStop"); //$NON-NLS-1$ keys.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { Rectangle rect = keys.getBounds(); Point pt = new Point(rect.x, rect.y + rect.height); pt = toolBar.toDisplay(pt); keysMenu.setLocation(pt.x, pt.y); keysMenu.setVisible(true); } }); new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL); XToolItem timeMode = new XToolItem(toolBar, SWT.CHECK | SWT.FLAT); timeMode.setImage(ImageManager.getSystemImage(SystemImage.ABSOLUTE)); timeMode.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.switchTimeMode"); //$NON-NLS-1$ timeMode.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { XToolItem itm = (XToolItem) e.widget; if (itm.getSelection()) { if (chart != null && start != null) { XYPlot plot = chart.getXYPlot(); DateAxis axis = new DateAxis(I18n.getString("LiveChartComposite.text.relativeTime")); //$NON-NLS-1$ RelativeDateFormat rdf = new RelativeDateFormat(start); axis.setDateFormatOverride(rdf); plot.setDomainAxis(axis); ValueAxis vaxis = plot.getDomainAxis(); vaxis.setAutoRange(true); vaxis.setFixedAutoRange(60000); } itm.setImage(ImageManager.getSystemImage(SystemImage.RELATIVE)); } else { if (chart != null) { XYPlot plot = chart.getXYPlot(); plot.setDomainAxis(new DateAxis(I18n.getString("LiveChartComposite.text.absoluteTime"))); //$NON-NLS-1$ ValueAxis vaxis = plot.getDomainAxis(); vaxis.setAutoRange(true); vaxis.setFixedAutoRange(60000); } itm.setImage(ImageManager.getSystemImage(SystemImage.ABSOLUTE)); } } }); new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL); startStop = new XToolItem(toolBar, SWT.CHECK | SWT.FLAT); startStop.setImage(ImageManager.getSystemImage(SystemImage.START)); startStop.setToolTipTextForLocaleKey("LiveChartComposite.tooltip.startOrStop"); //$NON-NLS-1$ startStop.setEnabled(false); startStop.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { final XToolItem itm = (XToolItem) e.widget; final boolean enabled = itm.getSelection(); keys.setEnabled(!enabled); if (enabled) { setPlottingEnabled(enabled); itm.setImage(ImageManager.getSystemImage(SystemImage.STOP)); } else { SWTUtil.showBusyWhile(getShell(), new Runnable() { public void run() { setPlottingEnabled(enabled); itm.setImage(ImageManager.getSystemImage(SystemImage.START)); } }); } } }); new ToolItem(toolBar, SWT.SEPARATOR | SWT.VERTICAL); // XToolItem thresholdItm = new XToolItem(toolBar, SWT.SEPARATOR); // thresholdItm.setWidth(75); // // //TODO: Double spinner, remove of old thres line // XSpinner threshold = new XSpinner(toolBar, SWT.BORDER); // threshold.setIncrement(1); // threshold.setMaximum(1); // threshold.setMaximum(Integer.MAX_VALUE); // threshold.setEnabled(false); // threshold.addSelectionListener(new SelectionAdapter( ) { // // /* (non-Javadoc) // * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) // */ // @Override // public void widgetSelected(SelectionEvent e) { // XSpinner spn = (XSpinner) e.widget; // double value = spn.getSelection( ); // if (chart != null && value > 0) { // XYPlot plot = (XYPlot) chart.getPlot( ); // Marker marker = new ValueMarker(value); // marker.setPaint(Color.orange); // marker.setAlpha(0.8f); // plot.addRangeMarker(marker); // } // } // // }); // thresholdItm.setControl(threshold); initKeysMenu(); cc = new XChartComposite(this, SWT.NONE, null, false, robotName); SWTUtil.setGridData(cc, false, true, SWT.FILL, SWT.FILL, 1, 1); }
From source file:org.n52.io.measurement.img.ChartIoHandler.java
private void configureTimeAxis(XYPlot xyPlot) { DateAxis timeAxis = (DateAxis) xyPlot.getDomainAxis(); timeAxis.setRange(getStartTime(getTimespan()), getEndTime(getTimespan())); String timeformat = "yyyy-MM-dd, HH:mm"; if (getChartStyleDefinitions().containsParameter("timeformat")) { timeformat = getChartStyleDefinitions().getAsString("timeformat"); }//w w w .ja v a2s.c o m DateFormat requestTimeFormat = new SimpleDateFormat(timeformat, i18n.getLocale()); requestTimeFormat.setTimeZone(getTimezone().toTimeZone()); timeAxis.setDateFormatOverride(requestTimeFormat); timeAxis.setTimeZone(getTimezone().toTimeZone()); }
From source file:com.orange.atk.graphAnalyser.CreateGraph.java
public long initializeTimeAxis() { Set<String> cles = mapPerfGraph.keySet(); Iterator<String> it = cles.iterator(); long initialvalue = 0; while (it.hasNext()) { String cle = (String) it.next(); PerformanceGraph graph = (PerformanceGraph) mapPerfGraph.get(cle); if (graph.getmintimestamp() < initialvalue || initialvalue == 0 && graph.getmintimestamp() != -1) { initialvalue = graph.getmintimestamp(); }/*from w ww. j ava2 s .c o m*/ } if (initialvalue == -1) { initialvalue = (new Date()).getTime(); } DateAxis axis = (DateAxis) xyplot.getDomainAxis(); // axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10)); RelativeDateFormat rdf = new RelativeDateFormat(initialvalue); rdf.setSecondFormatter(new DecimalFormat("00")); axis.setDateFormatOverride(rdf); return initialvalue; }
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 w w .jav a2 s. c o m 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(); } }