List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:org.toobsframework.pres.chart.ChartBuilder.java
private JFreeChart finishChart(IRequest componentRequest, ChartDefinition chartDef, Plot plot, Map params) { JFreeChart chart = new JFreeChart( ChartUtil.evaluateTextLabel(componentRequest, chartDef.getTitle(), params), ChartUtil.getFont(chartDef.getTitle(), JFreeChart.DEFAULT_TITLE_FONT), plot, chartDef.isShowLegend());// ww w .j a va 2 s. co m if (chartDef.getSubtitle() != null) { TextTitle subtitle = new TextTitle( ChartUtil.evaluateTextLabel(componentRequest, chartDef.getSubtitle(), params)); if (chartDef.getSubtitle().getFont() != null) { subtitle.setFont(ChartUtil.getFont(chartDef.getSubtitle(), null)); } subtitle.setPosition(ChartUtil.getPosition(chartDef.getSubtitle().getPosition())); subtitle.setPadding( ChartUtil.getRectangle(componentRequest, chartDef.getSubtitle().getPadding(), params)); subtitle.setVerticalAlignment( ChartUtil.getVerticalAlignment(chartDef.getSubtitle().getVerticalAlignment())); subtitle.setPaint(ChartUtil.getColor(chartDef.getSubtitle().getColor())); chart.addSubtitle(subtitle); } chart.setBackgroundPaint(ChartUtil.getColor(chartDef.getBackgroundColor())); if (chartDef.getTitle() != null && chartDef.getTitle().getColor() != null) { chart.getTitle().setPaint(ChartUtil.getColor(chartDef.getTitle().getColor())); } if (chartDef.isShowLegend()) { ChartUtil.configureLegend(componentRequest, chart, chartDef.getLegend(), params); } return chart; }
From source file:org.squale.squaleweb.util.graph.BubbleMaker.java
/** * Affichage sous la forme de sous-titres de la rpartition des mthodes - Maintenable et structur, - Maintenable * mais mal structur - Difficilement maintenable mais structur - Difficilement maintenable et mal structur * /*from www . j av a 2s . c o m*/ * @param pChart graphe de type Bubble */ private void displayRepartitionSubtitles(JFreeChart pChart) { double percentTopLeft = 0; double percentTopRight = 0; double percentBottomLeft = 0; double percentBottomRight = 0; int totalMethods = (int) (totalTopLeft + totalTopRight + totalBottomLeft + totalBottomRight); if (totalMethods > 0) { final int oneHundred = 100; // haut gauche : difficilement maintenable mais structur percentTopLeft = totalTopLeft * oneHundred / totalMethods; // haut droit : difficilement maintenable et mal structur percentTopRight = totalTopRight * oneHundred / totalMethods; // Bas gauche : maintenable et structur percentBottomLeft = totalBottomLeft * oneHundred / totalMethods; // Bas droit : maintenable mais mal structur percentBottomRight = totalBottomRight * oneHundred / totalMethods; } // Formatage des zones d'affichage NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(1); numberFormat.setMinimumFractionDigits(1); // Ajout du sous-titre de rpartition des mthodes avec le pourcentage correspondant : partie suprieure, coin // gauche et droit StringBuffer stringBufferTop = new StringBuffer(); stringBufferTop.append(WebMessages.getString(locale, "bubble.project.subtitle.topLeft") + " " + numberFormat.format(percentTopLeft) + "% "); stringBufferTop.append(WebMessages.getString(locale, "bubble.project.subtitle.topRight") + " " + numberFormat.format(percentTopRight) + "%"); TextTitle subtitleTop = new TextTitle(stringBufferTop.toString()); // Ajout du sous-titre de rpartition des mthodes avec le pourcentage correspondant : partie infrieure, coin // gauche et droit StringBuffer stringBufferBottom = new StringBuffer(); stringBufferBottom.append(WebMessages.getString(locale, "bubble.project.subtitle.bottomLeft") + " " + numberFormat.format(percentBottomLeft) + "% "); stringBufferBottom.append(WebMessages.getString(locale, "bubble.project.subtitle.bottomRight") + " " + numberFormat.format(percentBottomRight) + "%"); TextTitle subtitleBottom = new TextTitle(stringBufferBottom.toString()); // Les rpartitions sont ajoutes sous la forme de sous-menus subtitleBottom.setPosition(RectangleEdge.BOTTOM); pChart.addSubtitle(subtitleBottom); subtitleTop.setPosition(RectangleEdge.BOTTOM); pChart.addSubtitle(subtitleTop); }
From source file:edu.fullerton.ldvservlet.SrcList.java
private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage, ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException { PageItemList ret = new PageItemList(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)")); plot.setGap(10.0);/*from www .j a v a2 s .co m*/ String baseName = ""; StringBuilder errors = new StringBuilder(); int plotNum = 0; Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN }; boolean gotData = false; TimeInterval timeRange = null; for (ChanSourceData csd : csdList) { TimeInterval ti = csd.getTimeRange(); if (ti != null) { if (timeRange == null) { timeRange = ti; } else if (timeRange.overlaps(ti)) { timeRange = timeRange.mergeIntervals(ti); } else if (ti.getStartGps() < timeRange.getStartGps()) { timeRange.setStartGps(ti.getStartGps()); } else if (ti.getStopGps() > timeRange.getStopGps()) { timeRange.setStopGps(ti.getStopGps()); } } } if (timeRange != null) { for (ChanSourceData csd : csdList) { baseName = csd.getChanInfo().getBaseName(); TimeSeriesCollection mtds = new TimeSeriesCollection(); String server = csd.getChanInfo().getServer().replace(".caltech.edu", ""); String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server); TimeSeries ts; double[][] data = csd.getGraphData(); if (data == null) { data = new double[2][2]; data[0][0] = timeRange.getStartGps(); data[1][0] = timeRange.getStopGps(); data[0][1] = data[1][1] = 0; errors.append("Error getting data for: ").append(legend).append("<br>"); } else { gotData = true; } for (double[] d : data) { d[1] = d[1] <= 1 ? 1 : d[1]; } ts = getTimeSeries(data, legend); mtds.addSeries(ts); XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA); BasicStroke str = new BasicStroke(2); int colorIdx = plotNum % colors.length; Color color = colors[colorIdx]; NumberAxis yAxis = new NumberAxis("% Avail"); yAxis.setRange(0, 100); renderer.setBaseFillPaint(color); renderer.setSeriesFillPaint(0, Color.WHITE); renderer.setBaseStroke(str); renderer.setUseFillPaint(true); XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer); plot.add(subplot); plotNum++; } ChartPanel cpnl; JFreeChart chart; String gtitle = String.format("Available data for %1$s ", baseName); String subTitleTxt = String.format("From %1$s to %2$s", TimeAndDate.gpsAsUtcString(timeRange.getStartGps()), TimeAndDate.gpsAsUtcString(timeRange.getStopGps())); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle(subTitleTxt)); cpnl = new ChartPanel(chart, false, false, false, false, false); PluginSupport psupport = new PluginSupport(); psupport.setup(db, vpage, vuser); int imgId; PageItemImage img = null; try { psupport.setSize(800, 600); imgId = psupport.saveImageAsPNG(cpnl); String url = String.format("%1$s/view?act=getImg&imgId=%2$d", contextPath, imgId); img = new PageItemImage(url, "availability", baseName); } catch (SQLException | IOException | NoSuchAlgorithmException ex) { String ermsg = String.format("Error creating or saving image: %1$s - $2$s", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); errors.append(ermsg); } if (errors.length() > 0) { ret.add(errors.toString()); } if (img != null) { ret.add(img); } } else { ret.add("No data to plot."); } return ret; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
protected void initChart(JFreeChart chart, ChartModel chartModel) { if (chartModel.getBackground() instanceof Integer) { chart.setBackgroundPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBackground())); } else {/*from www. ja v a 2 s .com*/ chart.setBackgroundPaint(Color.WHITE); } if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { Font font = ChartUtils.getFont(chartModel.getTitle().getFontFamily(), chartModel.getTitle().getFontStyle(), chartModel.getTitle().getFontWeight(), chartModel.getTitle().getFontSize()); if (font != null) { chart.getTitle().setFont(font); } RectangleEdge rectangleEdge = RectangleEdge.TOP; if (chartModel.getTitle().getLocation() != null) { switch (chartModel.getTitle().getLocation()) { case RIGHT: rectangleEdge = RectangleEdge.BOTTOM; break; case LEFT: rectangleEdge = RectangleEdge.LEFT; break; case BOTTOM: rectangleEdge = RectangleEdge.BOTTOM; break; } } chart.getTitle().setPosition(rectangleEdge); if (RectangleEdge.isTopOrBottom(rectangleEdge)) { HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER; if (chartModel.getTitle().getAlignment() != null) { switch (chartModel.getTitle().getAlignment()) { case LEFT: horizontalAlignment = horizontalAlignment.LEFT; break; case RIGHT: horizontalAlignment = horizontalAlignment.RIGHT; break; } } chart.getTitle().setHorizontalAlignment(horizontalAlignment); } } if ((chartModel.getLegend() != null) && chartModel.getLegend().getVisible()) { Font font = ChartUtils.getFont(chartModel.getLegend().getFontFamily(), chartModel.getLegend().getFontStyle(), chartModel.getLegend().getFontWeight(), chartModel.getLegend().getFontSize()); if (font != null) { chart.getLegend().setItemFont(font); } if (!chartModel.getLegend().getBorderVisible()) { chart.getLegend().setFrame(BlockBorder.NONE); } } chart.setBorderVisible(chartModel.getBorderVisible()); if (chartModel.getBorderColor() instanceof Integer) { chart.setBorderPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBorderColor())); } for (StyledText subtitle : chartModel.getSubtitles()) { if ((subtitle.getText()) != null && (subtitle.getText().trim().length() > 0)) { TextTitle textTitle = new TextTitle(subtitle.getText()); Font font = ChartUtils.getFont(subtitle.getFontFamily(), subtitle.getFontStyle(), subtitle.getFontWeight(), subtitle.getFontSize()); if (font != null) { textTitle.setFont(font); } if (subtitle.getColor() != null) { textTitle.setPaint(new Color(0x00FFFFFF & subtitle.getColor())); } if (subtitle.getBackgroundColor() != null) { textTitle.setBackgroundPaint(new Color(0x00FFFFFF & subtitle.getBackgroundColor())); } chart.addSubtitle(textTitle); } } }
From source file:asl.util.PlotMaker.java
public void plotSpecAmp2(double freq[], double[] amp1, double[] phase1, double[] amp2, double[] phase2, String plotTitle, String pngName) { /**// ww w. j a v a2s . c o m final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); **/ File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } // Plot x-axis (frequency) range final double XMIN = .00009; final double XMAX = freq[freq.length - 1]; System.out.format("== plotSpecAmp2: nfreq=%d npts=%d pngName=%s\n", freq.length, amp2.length, pngName); final XYSeries series1 = new XYSeries("Amp_PZ"); final XYSeries series1b = new XYSeries("Amp_Cal"); final XYSeries series2 = new XYSeries("Phase_PZ"); final XYSeries series2b = new XYSeries("Phase_Cal"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = amp1[k]; //double dB = 20. * Math.log10( amp1[k] ); //series1.add( freq[k], dB ); //series1.add( freq[k], 20. * Math.log10( amp1[k] ) ); //series1b.add(freq[k], 20. * Math.log10( amp2[k] )); series1.add(freq[k], amp1[k]); series1b.add(freq[k], amp2[k]); series2.add(freq[k], phase1[k]); series2b.add(freq[k], phase2[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); //horizontalAxis.setRange( new Range(0.00009 , 110) ); horizontalAxis.setRange(new Range(XMIN, XMAX)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series1b); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); seriesCollection2.addSeries(series2b); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeChart(JFreeChart jfchart, ChartParams params) { // title//from ww w .j a v a 2s.c om if (params.get(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) { TextTitle title = new TextTitle(params.getString(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX)); customizeTitle(title, params, ChartParams.TITLE_PREFIX); jfchart.setTitle(title); } // subtitle if (params.get(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) { TextTitle subtitle = new TextTitle( params.getString(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX)); customizeTitle(subtitle, params, ChartParams.SUBTITLE_PREFIX); jfchart.addSubtitle(subtitle); } // legend LegendTitle legend = jfchart.getLegend(); customizeLegend(legend, params); // anti-alias if (params.get(ChartParams.ANTI_ALIAS) != null) { jfchart.setAntiAlias(params.getBoolean(ChartParams.ANTI_ALIAS).booleanValue()); } // background color if (params.get(ChartParams.BACKGROUND_COLOR) != null) { jfchart.setBackgroundPaint(params.getColor(ChartParams.BACKGROUND_COLOR)); } // border if (params.get(ChartParams.BORDER_VISIBLE) != null && params.getBoolean(ChartParams.BORDER_VISIBLE).booleanValue()) { jfchart.setBorderVisible(true); if (params.get(ChartParams.BORDER_COLOR) != null) { jfchart.setBorderPaint(params.getColor(ChartParams.BORDER_COLOR)); } if (params.get(ChartParams.BORDER_STROKE) != null) { jfchart.setBorderStroke(params.getStroke(ChartParams.BORDER_STROKE)); } } }
From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java
private void updateCanvas() { Rectangle bounds = canvas.getBounds(); if (bounds.width <= 0 || bounds.height <= 0) { return;/* w ww . j av a 2s . c o m*/ } // The list of snapshots : convert to JFreeChart dataset // DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String[] selectedSteps = stepsList.getSelection(); if (selectedSteps == null || selectedSteps.length == 0) { selectedSteps = new String[] { steps[0], }; // first step stepsList.select(0); } int[] dataIndices = dataList.getSelectionIndices(); if (dataIndices == null || dataIndices.length == 0) { dataIndices = new int[] { DATA_CHOICE_WRITTEN, }; dataList.select(0); } boolean multiStep = stepsList.getSelectionCount() > 1; boolean multiData = dataList.getSelectionCount() > 1; boolean calcMoving = !multiStep && !multiData; // A single metric shown for a single step List<Double> movingList = new ArrayList<Double>(); int movingSize = 10; double movingTotal = 0; int totalTimeInSeconds = 0; for (int t = 0; t < selectedSteps.length; t++) { String stepNameCopy = selectedSteps[t]; List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy); if (snapShotList != null && snapShotList.size() > 1) { totalTimeInSeconds = (int) Math .round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000); for (int i = 0; i < snapShotList.size(); i++) { StepPerformanceSnapShot snapShot = snapShotList.get(i); if (snapShot.getTimeDifference() != 0) { double factor = (double) 1000 / (double) snapShot.getTimeDifference(); for (int d = 0; d < dataIndices.length; d++) { String dataType; if (multiStep) { dataType = stepNameCopy; } else { dataType = dataChoices[dataIndices[d]]; } String xLabel = Integer.toString(Math.round(i * timeDifference / 1000)); Double metric = null; switch (dataIndices[d]) { case DATA_CHOICE_INPUT: metric = snapShot.getLinesInput() * factor; break; case DATA_CHOICE_OUTPUT: metric = snapShot.getLinesOutput() * factor; break; case DATA_CHOICE_READ: metric = snapShot.getLinesRead() * factor; break; case DATA_CHOICE_WRITTEN: metric = snapShot.getLinesWritten() * factor; break; case DATA_CHOICE_UPDATED: metric = snapShot.getLinesUpdated() * factor; break; case DATA_CHOICE_REJECTED: metric = snapShot.getLinesRejected() * factor; break; case DATA_CHOICE_INPUT_BUFFER_SIZE: metric = (double) snapShot.getInputBufferSize(); break; case DATA_CHOICE_OUTPUT_BUFFER_SIZE: metric = (double) snapShot.getOutputBufferSize(); break; default: break; } if (metric != null) { dataset.addValue(metric, dataType, xLabel); if (calcMoving) { movingTotal += metric; movingList.add(metric); if (movingList.size() > movingSize) { movingTotal -= movingList.get(0); movingList.remove(0); } double movingAverage = movingTotal / movingList.size(); dataset.addValue(movingAverage, dataType + "(Avg)", xLabel); // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m"); } } } } } } } String chartTitle = title; if (multiStep) { chartTitle += " (" + dataChoices[dataIndices[0]] + ")"; } else { chartTitle += " (" + selectedSteps[0] + ")"; } final JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), Long.toString(timeDifference)), // domain axis label BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false); // urls chart.setBackgroundPaint(Color.white); TextTitle title = new TextTitle(chartTitle); // title.setExpandToFitSpace(true); // org.eclipse.swt.graphics.Color pentahoColor = GUIResource.getInstance().getColorPentaho(); // java.awt.Color color = new java.awt.Color(pentahoColor.getRed(), pentahoColor.getGreen(),pentahoColor.getBlue()); // title.setBackgroundPaint(color); title.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12)); chart.setTitle(title); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.5f); plot.setRangeGridlinesVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelsVisible(false); // Customize the renderer... // LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setSeriesStroke(0, new BasicStroke(1.5f)); renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f)); renderer.setSeriesStroke(1, new BasicStroke(2.5f)); renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f)); renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB, null); ImageData imageData = ImageUtil.convertToSWT(bufferedImage); // dispose previous image... // if (image != null) { image.dispose(); } image = new Image(transGraph.getDisplay(), imageData); // Draw the image on the canvas... // canvas.redraw(); }
From source file:asl.util.PlotMaker.java
public void plotSpecAmp(double freq[], double[] amp, double[] phase, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/*from w w w . j a va 2 s. c o m*/ } final XYSeries series1 = new XYSeries("Amplitude"); final XYSeries series2 = new XYSeries("Phase"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = 20. * Math.log10(amp[k]); series1.add(freq[k], dB); series2.add(freq[k], phase[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); horizontalAxis.setRange(new Range(0.00009, 110)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); // Here we need to see if test dir exists and create it if necessary ... try { //ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300); //ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:CGgui.java
private void updateData() { //set up progress bar updateProgressbar("Updating data..."); //recalculate data //rebuild arrays MIN = Double.MAX_VALUE;/*ww w .j a v a 2 s . c om*/ MAX = 0; //grab last min for adjusting bounds double prevMin = CurrMin; if (fragmentMap.size() > 0) { //get lengths, use iterator to avoid concurrent modification exception Iterator it = fragmentMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry mapEntry = (Map.Entry) it.next(); Fragment f = (Fragment) mapEntry.getValue(); f.setPatternsPerFragment(CurrCG); //passed by reference } } //graph replaceData(key); //label chart chart.clearSubtitles(); chart.addSubtitle(0, new TextTitle("n = " + CurrCG)); //adjust min and max bounds adjustBounds(prevMin); //report new domain mindomainText.setText(Double.toString(MIN)); maxdomainText.setText(Double.toString(MAX)); //garbage collect //System.gc(); }
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 . java 2 s.com * @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"); }