List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:ch.agent.crnickl.demo.stox.Chart.java
private JFreeChart makeChart() throws KeyedException { if (chartSeries.size() == 0) throw new IllegalStateException("addChartSeries() not called"); if (range == null) { for (ChartSeries s : chartSeries) { if (range == null) range = s.getTimeSeries().getRange(); else// w w w . ja v a 2s . co m range = range.union(s.getTimeSeries().getRange()); } } // use number axis for dates, with special formatter DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(new CustomDateFormat("M/d/y")); if (range.getTimeDomain().getLabel().equals("workweek")) dateAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); // combined plot with shared date axis CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis); for (ChartSeries s : chartSeries) { makeSubPlot(plot, s); } // make the chart, remove the legend, set the title JFreeChart chart = new JFreeChart(plot); if (!withLegend) chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.setTitle(new TextTitle(title)); return chart; }
From source file:uk.co.moonsit.sockets.GraphClient.java
private void setSubtitles(JFreeChart chart, String[] labelsArray) { for (String label : labelsArray) { int axis = Integer.parseInt(label.substring(label.length() - 1, label.length())); TextTitle tt = new TextTitle(label); tt.setPaint(getAxisColor(axis - 1)); chart.addSubtitle(tt);/* w w w.jav a 2 s. com*/ } }
From source file:asl.util.PlotMaker.java
public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend, String eventString, String plotString) { // Expecting 9 channels packed like: Panel Trace1 Trace2 Trace3 // channels[0] = 00-LHZ 1 00-LHZ 10-LHZ 20-LHZ // channels[1] = 00-LHND 2 00-LHND 10-LHND 20-LHND // channels[2] = 00-LHED 3 00-LHED 10-LHED 20-LHED // channels[3] = 10-LHZ // channels[4] = 10-LHND // channels[5] = 10-LHED // channels[6] = 20-LHZ // channels[7] = 20-LHND // channels[8] = 20-LHED final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString); final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, 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("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/*www .ja va 2s .c o m*/ } if (channelData.size() != channels.length) { System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n", channels.length, channelData.size()); return; } XYSeries[] series = new XYSeries[channels.length]; for (int i = 0; i < channels.length; i++) { series[i] = new XYSeries(channels[i].toString()); double[] data = channelData.get(i); //for (int k = 0; k < xsecs.length; k++){ for (int k = 0; k < data.length; k++) { series[i].add(xsecs[k], data[k]); } } // I. Panel I = Verticals // Use the first data array, within the plotted range (nstart - nend) to scale the plots: double[] data = channelData.get(0); double ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green }; for (int i = 0; i < paints.length; i++) { renderer.setSeriesPaint(i, paints[i]); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } final NumberAxis verticalAxis = new NumberAxis("Displacement (m)"); verticalAxis.setRange(new Range(-ymax, ymax)); //verticalAxis.setTickUnit( new NumberTickUnit(5) ); final NumberAxis horizontalAxis = new NumberAxis("Time (s)"); horizontalAxis.setRange(new Range(nstart, nend)); //horizontalAxis.setRange( new Range(0.00009 , 110) ); final NumberAxis hAxis = new NumberAxis("Time (s)"); hAxis.setRange(new Range(nstart, nend)); final XYSeriesCollection seriesCollection1 = new XYSeriesCollection(); seriesCollection1.addSeries(series[0]); seriesCollection1.addSeries(series[3]); seriesCollection1.addSeries(series[6]); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer); final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer); double x = .95 * xsecs[nend]; double y = .90 * ymax; XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot1.addAnnotation(annotation1); // II. Panel II = North // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(1); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)"); verticalAxisN.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series[1]); seriesCollection2.addSeries(series[4]); seriesCollection2.addSeries(series[7]); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer); XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot2.addAnnotation(annotation2); // III. Panel III = East // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(2); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)"); verticalAxisE.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection3 = new XYSeriesCollection(); seriesCollection3.addSeries(series[2]); seriesCollection3.addSeries(series[5]); seriesCollection3.addSeries(series[8]); final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer); XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot3.addAnnotation(annotation3); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot1, 1); combinedPlot.add(xyplot2, 1); combinedPlot.add(xyplot3, 1); combinedPlot.setGap(15.); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:fr.amap.lidar.amapvox.chart.VoxelsToChart.java
public JFreeChart[] getVegetationProfileCharts(LayerReference reference, float maxPAD) { boolean inverseRangeAxis; inverseRangeAxis = !(reference == LayerReference.FROM_ABOVE_GROUND); int quadratNumber = getQuadratNumber(split, length); JFreeChart[] charts = new JFreeChart[quadratNumber]; for (int i = 0; i < quadratNumber; i++) { XYSeriesCollection dataset = new XYSeriesCollection(); for (VoxelFileChart voxelFile : voxelFiles) { int[] indices = getIndiceRange(voxelFile, i); XYSeries serie = createVegetationProfileSerie(voxelFile.reader, voxelFile.label, indices[0], indices[1], reference, maxPAD); dataset.addSeries(serie);/*w w w .jav a 2 s .c o m*/ } List<XYSeries> series = dataset.getSeries(); double correlationValue = Double.NaN; if (series.size() == 2) { XYSeries firstSerie = series.get(0); XYSeries secondSerie = series.get(1); Map<Double, Double[]> valuesMap = new HashMap<>(); for (int j = 0; j < firstSerie.getItemCount(); j++) { Double[] value = new Double[] { firstSerie.getDataItem(j).getXValue(), Double.NaN }; valuesMap.put(firstSerie.getDataItem(j).getYValue(), value); } for (int j = 0; j < secondSerie.getItemCount(); j++) { Double[] value = valuesMap.get(Double.valueOf(secondSerie.getDataItem(j).getYValue())); if (value == null) { valuesMap.put(secondSerie.getDataItem(j).getYValue(), new Double[] { Double.NaN, secondSerie.getDataItem(j).getXValue() }); } else if (Double.isNaN(value[1])) { value[1] = secondSerie.getDataItem(j).getXValue(); valuesMap.put(secondSerie.getDataItem(j).getYValue(), value); } } List<Double> firstList = new ArrayList<>(); List<Double> secondList = new ArrayList<>(); Iterator<Map.Entry<Double, Double[]>> iterator = valuesMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Double, Double[]> next = iterator.next(); Double[] value = next.getValue(); if (!Double.isNaN(value[0]) && !Double.isNaN(value[1])) { firstList.add(value[0]); secondList.add(value[1]); } } double[] firstArray = new double[firstList.size()]; double[] secondArray = new double[secondList.size()]; for (int j = 0; j < firstList.size(); j++) { firstArray[j] = firstList.get(j); secondArray[j] = secondList.get(j); } PearsonsCorrelation correlation = new PearsonsCorrelation(); correlationValue = correlation.correlation(firstArray, secondArray); } charts[i] = createChart("Vegetation profile" + " - quadrat " + (i + 1), dataset, "PAD", reference.getLabel()); if (!Double.isNaN(correlationValue)) { charts[i].addSubtitle( new TextTitle("R2 = " + (Math.round(Math.pow(correlationValue, 2) * 100)) / 100.0)); } ((XYPlot) charts[i].getPlot()).getRangeAxis().setInverted(inverseRangeAxis); } //set quadrats ranges double minX = 0; double maxX = 0; double minY = 0; double maxY = 0; int id = 0; for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); Range rangeOfRangeAxis = plot.getDataRange(plot.getRangeAxis()); Range rangeOfDomainAxis = plot.getDataRange(plot.getDomainAxis()); double currentMinY = rangeOfRangeAxis.getLowerBound(); double currentMaxY = rangeOfRangeAxis.getUpperBound(); double currentMinX = rangeOfDomainAxis.getLowerBound(); double currentMaxX = rangeOfDomainAxis.getUpperBound(); if (id == 0) { minX = currentMinX; maxX = currentMaxX; minY = currentMinY; maxY = currentMaxY; } else { if (currentMinX < minX) { minX = currentMinX; } if (currentMaxX > maxX) { maxX = currentMaxX; } if (currentMinY < minY) { minY = currentMinY; } if (currentMaxY > maxY) { maxY = currentMaxY; } } id++; } for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setRange(minX, maxX); plot.getRangeAxis().setRange(minY, maxY); } return charts; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Creates a sample chart.// w w w. j a v a2 s .co m * * @return a sample chart. */ private JFreeChart createChart() { final XYSeriesCollection primaryJFreeColl = new XYSeriesCollection(); final XYSeries left1 = new XYSeries("Left 1"); left1.add(1, 2); left1.add(2.8, 5.9); left1.add(3, null); left1.add(3.4, 2); left1.add(5, -1); left1.add(7, 1); primaryJFreeColl.addSeries(left1); final XYSeriesCollection secondaryJFreeColl = new XYSeriesCollection(); final XYSeries right1 = new XYSeries("Right 1"); right1.add(3.5, 2.2); right1.add(1.2, 1.3); right1.add(5.7, 4.1); right1.add(7.5, 7.4); secondaryJFreeColl.addSeries(right1); final NumberAxis xAxis = new NumberAxis("X"); xAxis.setAutoRangeIncludesZero(false); xAxis.setAutoRangeStickyZero(false); final NumberAxis primaryYAxis = new NumberAxis("Y1"); primaryYAxis.setAutoRangeIncludesZero(false); primaryYAxis.setAutoRangeStickyZero(false); // create plot final XYItemRenderer y1Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); y1Renderer.setSeriesPaint(0, Color.blue); y1Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); final XYPlot xyPlot = new XYPlot(primaryJFreeColl, xAxis, primaryYAxis, y1Renderer); // 2nd y-axis final NumberAxis secondaryYAxis = new NumberAxis("Y2"); secondaryYAxis.setAutoRangeIncludesZero(false); secondaryYAxis.setAutoRangeStickyZero(false); xyPlot.setRangeAxis(1, secondaryYAxis); xyPlot.setDataset(1, secondaryJFreeColl); xyPlot.mapDatasetToRangeAxis(1, 1); xyPlot.mapDatasetToDomainAxis(1, 1); final XYItemRenderer y2Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); y2Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); xyPlot.setRenderer(1, y2Renderer); // set some fixed y-dataranges and remember them // because default chartPanel.autoRangeBoth() // would destroy them ValueAxis axis = xyPlot.getRangeAxis(); this.primYMinMax[0] = -5; this.primYMinMax[1] = 15; axis.setLowerBound(this.primYMinMax[0]); axis.setUpperBound(this.primYMinMax[1]); axis = xyPlot.getRangeAxis(1); this.secondYMinMax[0] = -1; this.secondYMinMax[1] = 10; axis.setLowerBound(this.secondYMinMax[0]); axis.setUpperBound(this.secondYMinMax[1]); // Title + legend final String title = "To pan in zoom mode hold right mouse pressed"; final JFreeChart ret = new JFreeChart(title, null, xyPlot, true); final TextTitle textTitle = new TextTitle("(but you can only pan if the chart was zoomed before)"); ret.addSubtitle(textTitle); return ret; }
From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java
protected JFreeChart evaluateChart(byte evaluation) throws JRException { maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation); titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation); subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation); anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation); hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(), evaluation);/*from ww w . j av a 2s . com*/ hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(), evaluation); hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation); hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(), evaluation); hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(), expressionEvaluator, evaluation); dataset.evaluateDatasetRun(evaluation); dataset.finishDataset(); chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks()); bookmarkLevel = getChartSettings().getBookmarkLevel(); SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset()); if (getPlot().getAxisLineColor() != null) { spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor()); } if (getPlot().getAxisLineWidth() != null) { spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth())); } if (getPlot().getBackcolor() != null) { spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor()); } if (getPlot().getBackgroundAlpha() != null) { spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha()); } if (getPlot().getForegroundAlpha() != null) { spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha()); } if (getPlot().getHeadPercent() != null) { spiderWebPlot.setHeadPercent(getPlot().getHeadPercent()); } if (getPlot().getInteriorGap() != null) { spiderWebPlot.setInteriorGap(getPlot().getInteriorGap()); } if (getPlot().getLabelColor() != null) { spiderWebPlot.setLabelPaint(getPlot().getLabelColor()); } if (getPlot().getLabelFont() != null) { spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault())); } if (getPlot().getLabelGap() != null) { spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap()); } if (maxValue != null) { spiderWebPlot.setMaxValue(maxValue); } if (getPlot().getRotation() != null) { spiderWebPlot.setDirection(getPlot().getRotation().getRotation()); } if (getPlot().getStartAngle() != null) { spiderWebPlot.setStartAngle(getPlot().getStartAngle()); } if (getPlot().getTableOrder() != null) { spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder()); } if (getPlot().getWebFilled() != null) { spiderWebPlot.setWebFilled(getPlot().getWebFilled()); } spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator()); Font titleFont = getChartSettings().getTitleFont() != null ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true); if (chartSettings.getBackcolor() != null) { jfreechart.setBackgroundPaint(chartSettings.getBackcolor()); } RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP); if (titleText != null) { TextTitle title = jfreechart.getTitle(); title.setText(titleText); if (getChartSettings().getTitleColor() != null) { title.setPaint(getChartSettings().getTitleColor()); } title.setFont(titleFont); title.setPosition(titleEdge); jfreechart.setTitle(title); } if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setText(subtitleText); if (getChartSettings().getSubtitleColor() != null) { subtitle.setPaint(getChartSettings().getSubtitleColor()); } if (getChartSettings().getSubtitleColor() != null) { Font subtitleFont = getChartSettings().getSubtitleFont() != null ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; subtitle.setFont(subtitleFont); } subtitle.setPosition(titleEdge); jfreechart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreechart.getLegend(); if (legend != null) { legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend())); if (legend.isVisible()) { if (getChartSettings().getLegendColor() != null) { legend.setItemPaint(getChartSettings().getLegendColor()); } if (getChartSettings().getLegendBackgroundColor() != null) { legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor()); } if (getChartSettings().getLegendFont() != null) { legend.setItemFont( JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault())); } legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM)); } } return jfreechart; }
From source file:org.objectweb.proactive.benchmarks.timit.util.charts.BasicComparativeChartBuilder.java
/** * Creates a sample chart./* www .j a v a 2s .c om*/ * * @param dataset a dataset. * * @return The chart. */ private JFreeChart createChart() { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(this.chartTitle, // chart title "", // x axis label DEFAULT_Y_AXIS_NAME, // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.addSubtitle(new TextTitle(this.subtitle + "Time used is : " + TIME_ATTRIBUTE_NAME)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.black); plot.getRangeAxis().setLabelAngle((0 * Math.PI) / 2.0); ((BarRenderer) plot.getRenderer()).setItemMargin(0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.gridchem.client.gui.charts.UsageChart.java
private void init(CollaboratorBean collab) { removeAll();//from ww w . j a v a 2 s. c o m // TODO: Add title and footer with expiration date to chart String title = ""; ProjectBean project = projectCollabTable.keySet().iterator().next(); // if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { // dataset = createJobDataset(project); dataset = new DefaultPieDataset(); } else if (CURRENT_CHARTTYPE.equals(ChartType.PROJECT)) { dataset = createProjectDataset(projectCollabTable, collab); title = "Overall Utilization of Project " + project.getName() + " by " + collab.getFirstName() + " " + collab.getLastName(); ; } else if (CURRENT_CHARTTYPE.equals(ChartType.RESOURCE)) { dataset = createResourceDataset(projectCollabTable, collab); title = "CCG Resource Utilization for Project " + project.getName() + " by " + collab.getFirstName() + " " + collab.getLastName(); ; } else if (CURRENT_CHARTTYPE.equals(ChartType.USER)) { dataset = createUserDataset(projectCollabTable, collab); title = "User Utilization of Project " + project.getName() + " by " + collab.getFirstName() + " " + collab.getLastName(); } JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, // tooltips? false // URLs? ); chart.addSubtitle(new TextTitle("Project " + project.getName() + " expires on " + project.getEndDate())); if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { chart.getPlot().setNoDataMessage("Comprehensive job information is not currently available."); } ((PiePlot) chart.getPlot()).setCircular(true); // ((PiePlot)chart.getPlot()).setToolTipGenerator(new PieToolTipGenerator() { // // public String generateToolTip(PieDataset ds, Comparable arg1) { // // TODO Auto-generated method stub // return "; // } // // }); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(size); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; add(chartPanel, c); GridBagConstraints c1 = new GridBagConstraints(); c1.weightx = 0; c1.weighty = 0; c1.gridx = 0; c1.gridy = 1; c1.fill = GridBagConstraints.BOTH; add(navPanel, c1); revalidate(); }
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 . j ava2s .co m*/ 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:crossspectrumapp.CrossSpectrumApp.java
private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1, String subTitleText2) throws WebUtilException { XYSeries asdSeries = new XYSeries("asd"); XYSeries phiSeries = new XYSeries("phase"); for (int i = 1; i < frequency.length; i++) { double f = frequency[i]; double pwr = power[i]; double phi = phase[i]; asdSeries.add(f, pwr);// w ww .ja va2 s . c o m phiSeries.add(f, phi); } XYSeriesCollection asdCollection = new XYSeriesCollection(); asdCollection.addSeries(asdSeries); XYSeriesCollection phiCollection = new XYSeriesCollection(); phiCollection.addSeries(phiSeries); // create the chart XYItemRenderer asdRenderer = new StandardXYItemRenderer(); LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz"); XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYItemRenderer phiRenderer = new StandardXYItemRenderer(); NumberAxis phiAxis = new NumberAxis("Phase degrees"); XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)")); plot.setGap(10.0); // add the subplots... plot.add(asdSubplot, 2); plot.add(phiSubplot, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); Title subTitle = new TextTitle(subTitleText1); chart.addSubtitle(subTitle); subTitle = new TextTitle(subTitleText2); chart.addSubtitle(subTitle); ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY())); FileOutputStream fos = null; try { fos = new FileOutputStream(cscl.getOfileName()); ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY()); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }