List of usage examples for org.jfree.chart.plot XYPlot setDomainPannable
public void setDomainPannable(boolean pannable)
From source file:com.vgi.mafscaling.VECalc.java
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) { JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);//from w w w. j a v a2s. c o m chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); chartPanel.setMouseZoomable(false); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.CENTER; gbl_chartPanel.insets = new Insets(3, 3, 3, 3); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 1; plotPanel.add(chartPanel, gbl_chartPanel); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = 7593430826693873496L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis xAxis = new NumberAxis(xAxisName); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisName); yAxis.setAutoRangeIncludesZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); }
From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String propertyName, String morani) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false); plot.setRangePannable(false);//from ww w .j ava 2 s. c o m plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairLockedOnData(true); plot.setDomainCrosshairPaint(java.awt.Color.CYAN); plot.setRangeCrosshairPaint(java.awt.Color.CYAN); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); // 2. Setup Scatter plot // Create the scatter data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(propertyName); // ZScore xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis("lagged " + propertyName); //$NON-NLS-1$ yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot plotRenderer.setBaseToolTipGenerator(plotToolTip); // Set the scatter data, renderer, and axis into plot plot.setDataset(0, getScatterPlotData(features)); plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); // dot // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); plot.setDataset(1, getLinePlotData(crossCenter)); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY))); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend String title = "Moran's I = " + morani; //$NON-NLS-1$ java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(title, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method createChart.//from w w w .j a v a 2 s . 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:ispd.gui.auxiliar.Graficos.java
public void criarProcessamentoTempoUser(List<Tarefa> tarefas, RedeDeFilas rdf) { ArrayList<tempo_uso_usuario> lista = new ArrayList<tempo_uso_usuario>(); int numberUsers = rdf.getUsuarios().size(); Map<String, Integer> users = new HashMap<String, Integer>(); XYSeries tmp_series[] = new XYSeries[numberUsers]; XYSeries tmp_series1[] = new XYSeries[numberUsers]; Double utilizacaoUser[] = new Double[numberUsers]; Double utilizacaoUser1[] = new Double[numberUsers]; XYSeriesCollection dadosGrafico = new XYSeriesCollection(); XYSeriesCollection dadosGrafico1 = new XYSeriesCollection(); for (int i = 0; i < numberUsers; i++) { users.put(rdf.getUsuarios().get(i), i); utilizacaoUser[i] = 0.0;//from www. j a v a2 s .c o m tmp_series[i] = new XYSeries(rdf.getUsuarios().get(i)); utilizacaoUser1[i] = 0.0; tmp_series1[i] = new XYSeries(rdf.getUsuarios().get(i)); } if (!tarefas.isEmpty()) { //Insere cada tarefa como dois pontos na lista for (Tarefa task : tarefas) { CS_Processamento local = (CS_Processamento) task.getLocalProcessamento(); if (local != null) { for (int i = 0; i < task.getTempoInicial().size(); i++) { Double uso = (task.getHistoricoProcessamento().get(i).getPoderComputacional() / poderComputacionalTotal) * 100; tempo_uso_usuario provisorio1 = new tempo_uso_usuario(task.getTempoInicial().get(i), true, uso, users.get(task.getProprietario())); lista.add(provisorio1); tempo_uso_usuario provisorio2 = new tempo_uso_usuario(task.getTempoFinal().get(i), false, uso, users.get(task.getProprietario())); lista.add(provisorio2); } } } //Ordena lista Collections.sort(lista); } for (int i = 0; i < lista.size(); i++) { tempo_uso_usuario temp = (tempo_uso_usuario) lista.get(i); int usuario = temp.get_user(); //Altera os valores do usuario atual e todos acima dele for (int j = usuario; j < numberUsers; j++) { //Salva valores anteriores tmp_series[j].add(temp.get_tempo(), utilizacaoUser[j]); if (temp.get_tipo()) { utilizacaoUser[j] += temp.get_uso_no(); } else { utilizacaoUser[j] -= temp.get_uso_no(); } //Novo valor tmp_series[j].add(temp.get_tempo(), utilizacaoUser[j]); } //Grafico1 tmp_series1[usuario].add(temp.get_tempo(), utilizacaoUser1[usuario]); if (temp.get_tipo()) { utilizacaoUser1[usuario] += temp.get_uso_no(); } else { utilizacaoUser1[usuario] -= temp.get_uso_no(); } tmp_series1[usuario].add(temp.get_tempo(), utilizacaoUser1[usuario]); } for (int i = 0; i < numberUsers; i++) { dadosGrafico.addSeries(tmp_series[i]); dadosGrafico1.addSeries(tmp_series1[i]); } JFreeChart user1 = ChartFactory.createXYAreaChart("Use of total computing power through time" + "\nUsers", //Titulo "Time (seconds)", // Eixo X "Rate of total use of resources (%)", //Eixo Y dadosGrafico1, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, true, false); // exibir: legendas, tooltips, url JFreeChart user2 = ChartFactory.createXYLineChart("Use of total resources through time" + "\nUsers", //Titulo "Time (seconds)", // Eixo X "Rate of total use of resources (%)", //Eixo Y dadosGrafico, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, true, false); // exibir: legendas, tooltips, url XYPlot xyplot = (XYPlot) user2.getPlot(); xyplot.setDomainPannable(true); XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(2); xysteparearenderer.setDataBoundsIncludesVisibleSeriesOnly(false); xysteparearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); xysteparearenderer.setDefaultEntityRadius(6); xyplot.setRenderer(xysteparearenderer); UserThroughTimeChart1 = new ChartPanel(user1); UserThroughTimeChart1.setPreferredSize(new Dimension(600, 300)); UserThroughTimeChart2 = new ChartPanel(user2); UserThroughTimeChart2.setPreferredSize(new Dimension(600, 300)); }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false); plot.setRangePannable(false);/*from w ww. ja v a 2 s . c o m*/ plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.75f); // 2. Setup Scatter plot // Create the bubble chart data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator()); plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plotRenderer .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // Set the bubble chart data, renderer, and axis into plot plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED); plot.setDataset(2, new DefaultXYZDataset2()); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:com.vgi.mafscaling.MafCompare.java
/** * Initialize the contents of the frame. *//*from w ww . j a va 2 s . c om*/ private void initialize() { try { ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg")); setTitle(Title); setIconImage(tableImage.getImage()); setBounds(100, 100, 621, 372); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); setSize(Config.getCompWindowSize()); setLocation(Config.getCompWindowLocation()); setLocationRelativeTo(null); setVisible(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Utils.clearTable(origMafTable); Utils.clearTable(newMafTable); Utils.clearTable(compMafTable); Config.setCompWindowSize(getSize()); Config.setCompWindowLocation(getLocation()); origMafData.clear(); newMafData.clear(); } }); JPanel dataPanel = new JPanel(); GridBagLayout gbl_dataPanel = new GridBagLayout(); gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 }; gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 }; gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 }; gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; dataPanel.setLayout(gbl_dataPanel); getContentPane().add(dataPanel); JLabel origLabel = new JLabel(origMaf); GridBagConstraints gbc_origLabel = new GridBagConstraints(); gbc_origLabel.anchor = GridBagConstraints.PAGE_START; gbc_origLabel.insets = new Insets(1, 1, 1, 5); gbc_origLabel.weightx = 0; gbc_origLabel.weighty = 0; gbc_origLabel.gridx = 0; gbc_origLabel.gridy = 0; gbc_origLabel.gridheight = 2; dataPanel.add(origLabel, gbc_origLabel); JLabel newLabel = new JLabel(newMaf); GridBagConstraints gbc_newLabel = new GridBagConstraints(); gbc_newLabel.anchor = GridBagConstraints.PAGE_START; gbc_newLabel.insets = new Insets(1, 1, 1, 5); gbc_newLabel.weightx = 0; gbc_newLabel.weighty = 0; gbc_newLabel.gridx = 0; gbc_newLabel.gridy = 2; gbc_newLabel.gridheight = 2; dataPanel.add(newLabel, gbc_newLabel); JLabel compLabel = new JLabel("Change"); GridBagConstraints gbc_compLabel = new GridBagConstraints(); gbc_compLabel.anchor = GridBagConstraints.PAGE_START; gbc_compLabel.insets = new Insets(1, 1, 1, 5); gbc_compLabel.weightx = 0; gbc_compLabel.weighty = 0; gbc_compLabel.gridx = 0; gbc_compLabel.gridy = 4; dataPanel.add(compLabel, gbc_compLabel); JLabel origVoltLabel = new JLabel("volt"); GridBagConstraints gbc_origVoltLabel = new GridBagConstraints(); gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_origVoltLabel.weightx = 0; gbc_origVoltLabel.weighty = 0; gbc_origVoltLabel.gridx = 1; gbc_origVoltLabel.gridy = 0; dataPanel.add(origVoltLabel, gbc_origVoltLabel); JLabel origGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_origGsLabel = new GridBagConstraints(); gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_origGsLabel.insets = new Insets(1, 1, 1, 5); gbc_origGsLabel.weightx = 0; gbc_origGsLabel.weighty = 0; gbc_origGsLabel.gridx = 1; gbc_origGsLabel.gridy = 1; dataPanel.add(origGsLabel, gbc_origGsLabel); JLabel newVoltLabel = new JLabel("volt"); GridBagConstraints gbc_newVoltLabel = new GridBagConstraints(); gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_newVoltLabel.weightx = 0; gbc_newVoltLabel.weighty = 0; gbc_newVoltLabel.gridx = 1; gbc_newVoltLabel.gridy = 2; dataPanel.add(newVoltLabel, gbc_newVoltLabel); JLabel newGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_newGsLabel = new GridBagConstraints(); gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_newGsLabel.insets = new Insets(1, 1, 1, 5); gbc_newGsLabel.weightx = 0; gbc_newGsLabel.weighty = 0; gbc_newGsLabel.gridx = 1; gbc_newGsLabel.gridy = 3; dataPanel.add(newGsLabel, gbc_newGsLabel); JLabel compPctLabel = new JLabel(" % "); GridBagConstraints gbc_compPctLabel = new GridBagConstraints(); gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START; gbc_compPctLabel.insets = new Insets(1, 1, 1, 5); gbc_compPctLabel.weightx = 0; gbc_compPctLabel.weighty = 0; gbc_compPctLabel.gridx = 1; gbc_compPctLabel.gridy = 4; dataPanel.add(compPctLabel, gbc_compPctLabel); JPanel tablesPanel = new JPanel(); GridBagLayout gbl_tablesPanel = new GridBagLayout(); gbl_tablesPanel.columnWidths = new int[] { 0 }; gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_tablesPanel.columnWeights = new double[] { 0.0 }; gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 }; tablesPanel.setLayout(gbl_tablesPanel); JScrollPane mafScrollPane = new JScrollPane(tablesPanel); mafScrollPane.setMinimumSize(new Dimension(1600, 107)); mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20)); mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagConstraints gbc_mafScrollPane = new GridBagConstraints(); gbc_mafScrollPane.weightx = 1.0; gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START; gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL; gbc_mafScrollPane.gridx = 2; gbc_mafScrollPane.gridy = 0; gbc_mafScrollPane.gridheight = 5; dataPanel.add(mafScrollPane, gbc_mafScrollPane); origMafTable = new JTable(); origMafTable.setColumnSelectionAllowed(true); origMafTable.setCellSelectionEnabled(true); origMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); origMafTable.setRowHeight(RowHeight); origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); origMafTable.setTableHeader(null); Utils.initializeTable(origMafTable, ColumnWidth); GridBagConstraints gbc_origMafTable = new GridBagConstraints(); gbc_origMafTable.anchor = GridBagConstraints.PAGE_START; gbc_origMafTable.insets = new Insets(0, 0, 0, 0); gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_origMafTable.weightx = 1.0; gbc_origMafTable.weighty = 0; gbc_origMafTable.gridx = 0; gbc_origMafTable.gridy = 0; tablesPanel.add(origMafTable, gbc_origMafTable); excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true); newMafTable = new JTable(); newMafTable.setColumnSelectionAllowed(true); newMafTable.setCellSelectionEnabled(true); newMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); newMafTable.setRowHeight(RowHeight); newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); newMafTable.setTableHeader(null); Utils.initializeTable(newMafTable, ColumnWidth); GridBagConstraints gbc_newMafTable = new GridBagConstraints(); gbc_newMafTable.anchor = GridBagConstraints.PAGE_START; gbc_newMafTable.insets = new Insets(0, 0, 0, 0); gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_newMafTable.weightx = 1.0; gbc_newMafTable.weighty = 0; gbc_newMafTable.gridx = 0; gbc_newMafTable.gridy = 1; tablesPanel.add(newMafTable, gbc_newMafTable); excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true); compMafTable = new JTable(); compMafTable.setColumnSelectionAllowed(true); compMafTable.setCellSelectionEnabled(true); compMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); compMafTable.setRowHeight(RowHeight); compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount)); compMafTable.setTableHeader(null); Utils.initializeTable(compMafTable, ColumnWidth); NumberFormatRenderer numericRenderer = new NumberFormatRenderer(); numericRenderer.setFormatter(new DecimalFormat("0.000")); compMafTable.setDefaultRenderer(Object.class, numericRenderer); GridBagConstraints gbc_compMafTable = new GridBagConstraints(); gbc_compMafTable.anchor = GridBagConstraints.PAGE_START; gbc_compMafTable.insets = new Insets(0, 0, 0, 0); gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_compMafTable.weightx = 1.0; gbc_compMafTable.weighty = 0; gbc_compMafTable.gridx = 0; gbc_compMafTable.gridy = 2; tablesPanel.add(compMafTable, gbc_compMafTable); compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true); TableModelListener origTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = origMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, newMafTable); Utils.ensureColumnCount(colCount, compMafTable); origMafData.clear(); String origY, origX, newY; for (int i = 0; i < colCount; ++i) { origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) { origX = origMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, origX)) origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false); newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } origMafData.fireSeriesChanged(); } } }; TableModelListener newTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = newMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, origMafTable); Utils.ensureColumnCount(colCount, compMafTable); newMafData.clear(); String newY, newX, origY; for (int i = 0; i < colCount; ++i) { newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) { newX = newMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, newX)) newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false); origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } newMafData.fireSeriesChanged(); } } }; origMafTable.getModel().addTableModelListener(origTableListener); newMafTable.getModel().addTableModelListener(newTableListener); Action action = new AbstractAction() { private static final long serialVersionUID = 8148393537657380215L; public void actionPerformed(ActionEvent e) { TableCellListener tcl = (TableCellListener) e.getSource(); if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) { if (Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, tcl.getColumn()).toString())) { double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString()) / 100.0 + 1.0; newMafTable.setValueAt( Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr, 1, tcl.getColumn()); } } else compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn()); } }; setCompMafCellListener(new TableCellListener(compMafTable, action)); // CHART JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.PAGE_START; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.insets = new Insets(1, 1, 1, 1); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 5; gbl_chartPanel.gridheight = 1; gbl_chartPanel.gridwidth = 3; dataPanel.add(chartPanel, gbl_chartPanel); XYSplineRenderer lineRenderer = new XYSplineRenderer(3); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesStroke(1, stroke); lineRenderer.setSeriesPaint(0, new Color(201, 0, 0)); lineRenderer.setSeriesPaint(1, new Color(0, 0, 255)); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = -4045338273187150888L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis mafvDomain = new NumberAxis(XAxisName); mafvDomain.setAutoRangeIncludesZero(false); mafvDomain.setAutoRange(true); mafvDomain.setAutoRangeStickyZero(false); NumberAxis mafgsRange = new NumberAxis(YAxisName); mafgsRange.setAutoRangeIncludesZero(false); mafgsRange.setAutoRange(true); mafgsRange.setAutoRangeStickyZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); origMafData.setDescription(origMaf); newMafData.setDescription(newMaf); lineDataset.addSeries(origMafData); lineDataset.addSeries(newMafData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, mafvDomain); plot.setRangeAxis(0, mafgsRange); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); } catch (Exception e) { logger.error(e); } }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.SimpleXY_ChartPanel.java
private JFreeChart createChart(XY_PlotType type, Object userObject, Object userElement) { SMT_UpdateService updateService = SMT_UpdateService.getInstance(); OMS_Collection history = updateService.getCollection(); if ((history == null) || (history.getSize() < 2)) { // need at least two datapoints to this chart to make sense logger.severe("OMS Delta unavailable, cannot createChart(), must wait for more historical snapshots"); MessageManager.getInstance().postMessage( new SmtMessage(SmtMessageType.SMT_MSG_SEVERE, "Cannot build chart without historical data")); return null; }//from w w w . jav a2 s . c om MessageManager.getInstance() .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building Plot")); long deltaPeriod = history.getAveDeltaSeconds(); // the primary dataset of the desired counter which will be axis1 XYDataset dataset1 = createDataset(history, userObject, userElement); // most axis are in counts (and delta counts) but utilization is in percentages String axisLabel = isUtilizationType() ? PortCounterAxisLabel.UTIL_AVE.getName() : PortCounterAxisLabel.COUNTS.getName(); // setup the chart for the desired counter JFreeChart chart = ChartFactory.createTimeSeriesChart(getChartTitle(), "Time of Day", axisLabel, dataset1, true, true, false); if (isUtilizationType()) { chart.addSubtitle(new TextTitle(AnalysisType.getAnalysisName() + " (" + deltaPeriod + " sec. delta)")); // chart.addSubtitle(new TextTitle("number of ports")); } else chart.addSubtitle(new TextTitle(type.getName() + " Activity (" + deltaPeriod + " sec. delta)")); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainPannable(true); plot.setRangePannable(true); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:org.glotaran.core.datadisplayers.multispec.MultiSpecEditorTopComponent.java
private JFreeChart createChart(XYDataset dataset1) { JFreeChart chart_temp = ChartFactory.createScatterPlot(null, null, null, dataset1, PlotOrientation.VERTICAL, false, false, false);/*from w ww . j ava2 s . co m*/ double range = Math.abs(data.getMaxInt() - data.getMinInt()); double dataMin, dataMax; if (range == 0.0) { dataMin = data.getMinInt() - 0.1; dataMax = data.getMaxInt() + 0.1; } else { dataMin = data.getMinInt(); dataMax = data.getMaxInt(); } PaintScale ps = new RainbowPaintScale(dataMin, dataMax); // PaintScale ps = new RedGreenPaintScale(dataMin, dataMax); BufferedImage image = ImageUtilities.createColorCodedImage(this.dataset, ps); XYDataImageAnnotation ann = new XYDataImageAnnotation(image, 0, 0, dataset.GetImageWidth(), dataset.GetImageHeigth(), true); XYPlot plot = (XYPlot) chart_temp.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setVisible(false); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setVisible(false); return chart_temp; }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void StackedXYAreaRenderer(ArrayList<Integer> arCpuArrayList, ArrayList<Integer> arWifiArrayList, ArrayList<Integer> arLedArrayList, ArrayList<Integer> arGpsArrayList, ArrayList<Integer> arAudioArrayList, ArrayList<Integer> arThreeGArrayList) { boolean flagGPS, flagAUDIO; flagGPS = mGPSCheckBox.isSelected(); flagAUDIO = mAudioCheckBox.isSelected(); XYSeries xyseriesCPU = new XYSeries("CPU"); XYSeries xyseriesWIFI = new XYSeries("WIFI"); XYSeries xyseriesThreeG = new XYSeries("3G"); XYSeries xyseriesLED = new XYSeries("LED"); XYSeries xyseriesGPS = new XYSeries("GPS"); XYSeries xyseriesAUDIO = new XYSeries("AUDIO"); for (int i = 0; i < arCpuArrayList.size(); i++) { //Power Tutor Bug if (arCpuArrayList.get(i) > 450) { arCpuArrayList.set(i, 450);/*w w w . j a va 2 s .c om*/ } /* * stack ? (Top -> bottom) * AUDIO / GPS / LED / ThreeG / WIFI / CPU */ xyseriesCPU.add(i, arCpuArrayList.get(i)); xyseriesWIFI.add(i, arWifiArrayList.get(i) + arCpuArrayList.get(i)); xyseriesThreeG.add(i, arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); xyseriesLED.add(i, arLedArrayList.get(i) + arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); if (flagGPS == true && flagAUDIO == true) { xyseriesGPS.add(i, arGpsArrayList.get(i) + arLedArrayList.get(i) + arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); xyseriesAUDIO.add(i, arAudioArrayList.get(i) + arGpsArrayList.get(i) + arLedArrayList.get(i) + arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); } else if (flagGPS == true && flagAUDIO == false) { xyseriesGPS.add(i, arGpsArrayList.get(i) + arLedArrayList.get(i) + arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); xyseriesAUDIO.add(i, 0); // AUDIO ? . } else if (flagGPS == false && flagAUDIO == true) { xyseriesGPS.add(i, 0); //GPS ? . xyseriesAUDIO.add(i, arAudioArrayList.get(i) + arLedArrayList.get(i) + arThreeGArrayList.get(i) + arWifiArrayList.get(i) + arCpuArrayList.get(i)); } else { xyseriesGPS.add(i, 0); //GPS ? . xyseriesAUDIO.add(i, 0); // AUDIO ? . } } XYSeriesCollection xyseriescollection = new XYSeriesCollection(); xyseriescollection.addSeries(xyseriesCPU); xyseriescollection.addSeries(xyseriesWIFI); xyseriescollection.addSeries(xyseriesThreeG); xyseriescollection.addSeries(xyseriesLED); xyseriescollection.addSeries(xyseriesGPS); xyseriescollection.addSeries(xyseriesAUDIO); JFreeChart jfreechart = ChartFactory.createXYLineChart("", "Time(sec)", "Power(mW)", xyseriescollection, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainPannable(true); xyplot.setBackgroundPaint(new Color(255, 255, 255));//? . XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(2); //?? ? . ?? /*xysteparearenderer.setSeriesPaint(0, new Color(0,0,0)); xysteparearenderer.setSeriesPaint(1, new Color(30,30,30)); xysteparearenderer.setSeriesPaint(2, new Color(60,60,60)); xysteparearenderer.setSeriesPaint(3, new Color(90,90,90)); xysteparearenderer.setSeriesPaint(4, new Color(120,120,120)); xysteparearenderer.setSeriesPaint(5, new Color(150,150,150));*/ xysteparearenderer.setDataBoundsIncludesVisibleSeriesOnly(false); xysteparearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); xysteparearenderer.setDefaultEntityRadius(6); xyplot.setRenderer(xysteparearenderer); ChartPanel chartPanel = new ChartPanel(jfreechart); JFrame f = new JFrame("StackedXYAreaRenderer"); f.setSize(600, 600); f.getContentPane().add(chartPanel); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java
/** * Zeichne die eigentliche Grafik Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * /*from w w w . j a va 2s .c om*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.07.2012 * @param dbId * dbid in Tabelle D_TABLE_DIVEDETAIL * @param device */ private void makeGraphForLog(int dbId, String device) { Vector<Integer[]> diveList; Vector<String> diluents; int[] headData; XYPlot thePlot; JFreeChart logChart; int min, sec; // das alte Zeug entsorgen releaseGraph(); // // Daten eines TG lesen // lg.debug("read dive log from DB..."); diveList = databaseUtil.getDiveDataFromIdLog(dbId); if (diveList == null || diveList.isEmpty()) { return; } // // verwendete Diluents finden // diluents = getDiluentNamesFromDive(diveList); // Anzeigen String diluentString = StringUtils.join(diluents, ", "); diluentLabel.setText( String.format(LangStrings.getString("spx42LogGraphPanel.diluentLabel.text"), diluentString)); lg.debug(diluents); // // Labels fr Tachgangseckdaten fllen // headData = databaseUtil.getHeadDiveDataFromIdLog(dbId); notesLabel.setText(databaseUtil.getNotesForIdLog(dbId)); showingUnitSystem = SpxPcloggerProgramConfig.unitsProperty; savedUnitSystem = headData[6]; // jetzt die Strings fr Masseinheiten holen String[] labels = getUnitsLabel(showingUnitSystem, savedUnitSystem); depthUnitName = labels[0]; tempUnitName = labels[1]; pressureUnitName = labels[2]; // // entscheide ob etwas umgerechnet werden sollte // if (showingUnitSystem == savedUnitSystem || showingUnitSystem == ProjectConst.UNITS_DEFAULT) { // nein, alles schick maxDepthValueLabel.setText(String.format(maxDepthLabelString, (headData[3] / 10.0), depthUnitName)); coldestTempValueLabel.setText(String.format(coldestLabelString, (headData[2] / 10.0), tempUnitName)); } else { // umrechnen! if (showingUnitSystem == ProjectConst.UNITS_IMPERIAL) { // metrisch-> imperial konvertieren // 1 foot == 30,48 cm == 0.3048 Meter maxDepthValueLabel .setText(String.format(maxDepthLabelString, (headData[3] / 10.0) / 0.3048, depthUnitName)); // t F = 5?9 (t 32) C coldestTempValueLabel.setText( String.format(coldestLabelString, (5.0 / 9.0) * ((headData[2] / 10.0) - 32), tempUnitName)); } else { maxDepthValueLabel .setText(String.format(maxDepthLabelString, (headData[3] / 10.0) * 0.3048, depthUnitName)); // t C = (9?5 t + 32) F coldestTempValueLabel.setText( String.format(coldestLabelString, ((9.0 / 5.0) * (headData[2] / 10.0)) + 32, tempUnitName)); } } min = headData[5] / 60; sec = headData[5] % 60; diveLenValueLabel.setText(String.format(diveLenLabelString, min, sec, "min")); // // einen Plot machen (Grundlage des Diagramms) // lg.debug("create graph..."); thePlot = new XYPlot(); // // Eigenschaften definieren // thePlot.setBackgroundPaint(Color.lightGray); thePlot.setDomainGridlinesVisible(true); thePlot.setDomainGridlinePaint(Color.white); thePlot.setRangeGridlinesVisible(true); thePlot.setRangeGridlinePaint(Color.white); thePlot.setDomainPannable(true); thePlot.setRangePannable(false); // // ein Chart zur Anzeige in einem Panel erzeugen // logChart = new JFreeChart(LangStrings.getString("spx42LogGraphPanel.graph.chartTitle"), thePlot); logChart.setAntiAlias(true); logChart.addSubtitle(new TextTitle(LangStrings.getString("spx42LogGraphPanel.graph.chartSubTitle"))); // ein Thema zufgen, damit ich eigene Farben einbauen kann ChartUtilities.applyCurrentTheme(logChart); // // ein Diagramm-Panel erzeugen // chartPanel = new ChartPanel(logChart); chartPanel.setMouseZoomable(true); chartPanel.setAutoscrolls(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setRangeZoomable(false); chartPanel.setDisplayToolTips(false); chartPanel.setZoomTriggerDistance(10); add(chartPanel, BorderLayout.CENTER); // // Datumsachse umformatieren // final NumberAxis axis = new NumberAxis(LangStrings.getString("spx42LogGraphPanel.graph.dateAxisTitle")); MinuteFormatter formatter = new MinuteFormatter( LangStrings.getString("spx42LogGraphPanel.graph.dateAxisUnit")); axis.setNumberFormatOverride(formatter); thePlot.setDomainAxis(axis); // // Temperatur einfgen // if (SpxPcloggerProgramConfig.showTemperature) { makeTemperatureGraph(diveList, thePlot, labels); } // // Partialdruck einfgen // die Achse erst mal machen final NumberAxis ppo2Axis = new NumberAxis( LangStrings.getString("spx42LogGraphPanel.graph.ppo2AxisTitle") + " " + pressureUnitName); final NumberAxis percentAxis = new NumberAxis(LangStrings.getString("spx42LogGraphPanel.graph.inertgas")); // // wenn eine der Achsen dargesstellt werden muss, dann sollte die Achse auch in der Grafil da sein // if (SpxPcloggerProgramConfig.showPpo01 || SpxPcloggerProgramConfig.showPpo02 || SpxPcloggerProgramConfig.showPpo03 || SpxPcloggerProgramConfig.showPpoResult || SpxPcloggerProgramConfig.showSetpoint) { ppo2Axis.setAutoRangeIncludesZero(false); ppo2Axis.setAutoRange(false); // // wie skaliere ich die Achse? // if (showingUnitSystem == ProjectConst.UNITS_DEFAULT) { // so wie gespeichert if (savedUnitSystem == ProjectConst.UNITS_METRIC) { ppo2Axis.setRange(0.0, 3.5); } else { ppo2Axis.setRange(0.0, (3.5 * 14.504)); } } else if (showingUnitSystem == ProjectConst.UNITS_METRIC) { ppo2Axis.setRange(0.0, 3.5); } else { ppo2Axis.setRange(0.0, (3.5 * 14.504)); } ppo2Axis.setLabelPaint(new Color(ProjectConst.GRAPH_PPO2ALL_ACOLOR)); ppo2Axis.setTickLabelPaint(new Color(ProjectConst.GRAPH_PPO2ALL_ACOLOR)); thePlot.setRangeAxis(GRAPH_PPO2ALL, ppo2Axis); } if (SpxPcloggerProgramConfig.showHe || SpxPcloggerProgramConfig.showN2) { percentAxis.setAutoRangeIncludesZero(false); percentAxis.setAutoRange(false); percentAxis.setRange(0.0, 100.0); percentAxis.setLabelPaint(new Color(ProjectConst.GRAPH_INNERTGAS_ACOLOR)); percentAxis.setTickLabelPaint(new Color(ProjectConst.GRAPH_INNERTGAS_ACOLOR)); thePlot.setRangeAxis(GRAPH_HE, percentAxis); } // // Partialdrcke der einzelnen Sensoren einfgen // // Sensor 01 anzeigen if (SpxPcloggerProgramConfig.showPpo01) { makePpoGraph(diveList, thePlot, 1); } // Sensor 02 anzeigen if (SpxPcloggerProgramConfig.showPpo02) { makePpoGraph(diveList, thePlot, 2); } // Sensor 03 anzeigen if (SpxPcloggerProgramConfig.showPpo03) { makePpoGraph(diveList, thePlot, 3); } // Resultierenden PPO anzeigen if (SpxPcloggerProgramConfig.showPpoResult) { makePpoGraph(diveList, thePlot, 0); // makePpoResultGraph( diveList, thePlot ); } if (SpxPcloggerProgramConfig.showSetpoint) { makeSetpointGraph(diveList, thePlot); } // // Helium und Stickstoffanteil im Gas? // if (SpxPcloggerProgramConfig.showHe) { makeInnertGasGraph(diveList, thePlot, "he"); } if (SpxPcloggerProgramConfig.showN2) { makeInnertGasGraph(diveList, thePlot, "n2"); } // // die Nullzeit auf Wunsch // if (SpxPcloggerProgramConfig.showNulltime) { makeNulltimeGraph(diveList, thePlot); } // // die Tiefe einfgen // makeDepthGraph(diveList, thePlot); // showingDbIdForDiveWasShowing = dbId; lg.debug("create graph...OK"); }