List of usage examples for org.jfree.chart.axis NumberAxis setLabelFont
public void setLabelFont(Font font)
From source file:com.att.aro.main.ProperSessionTerminationPanel.java
/** * Initializes the Panel for Proper Session Termination plot. *///from ww w . j a va 2 s.c o m private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = rb.getString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = rb.getString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = rb.getString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = rb.getString("tooltip.sessionLongBurst"); break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:com.att.aro.main.TraceOverviewPanel.java
/** * Initializes the Main panel and its various components. *//*from w ww.ja v a2 s. c o m*/ private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis valueRangeAxis = plot.getDomainAxis(); valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f); valueRangeAxis.setMaximumCategoryLabelLines(2); valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT); valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentile")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String traceInfo = ""; switch (arg2) { case TRACE_AVERAGE: traceInfo = rb.getString("tooltip.traceAnalysis.avg"); break; case TRACE_ENERGY: traceInfo = rb.getString("tooltip.traceAnalysis.engy"); break; case TRACE_OVERHEAD: traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd"); break; } return traceInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:charts.Chart.java
public static void BarChart(DefaultCategoryDataset dataset, String title, String x_axis_label, String y_axis_label, boolean showlegend) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createStackedBarChart(title, x_axis_label, y_axis_label, dataset, PlotOrientation.HORIZONTAL, showlegend, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); CategoryAxis domainaxis = categoryplot.getDomainAxis(); domainaxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel);//from ww w. j a v a 2 s .co m chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String[] fields) { // Setup Box plot int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; CategoryAxis xPlotAxis = new CategoryAxis(EMPTY); // Type xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 12)); NumberAxis yPlotAxis = new NumberAxis("Value"); // Value //$NON-NLS-1$ yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); yPlotAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMedianVisible(true);//from www . j a va 2s . com renderer.setMeanVisible(false); renderer.setFillBox(true); renderer.setSeriesFillPaint(0, java.awt.Color.CYAN); renderer.setBaseFillPaint(java.awt.Color.CYAN); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // Set the scatter data, renderer, and axis into plot CategoryDataset dataset = getDataset(features, fields); CategoryPlot plot = new CategoryPlot(dataset, xPlotAxis, yPlotAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setRangePannable(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.85f); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup Selection /***************************************************************************************** * CategoryAxis xSelectionAxis = new CategoryAxis(EMPTY); * xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); * * NumberAxis ySelectionAxis = new NumberAxis(EMPTY); * ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); * * BoxAndWhiskerRenderer selectionRenderer = new BoxAndWhiskerRenderer(); * selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); * selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot * * plot.setDataset(2, new DefaultBoxAndWhiskerCategoryDataset()); 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:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; }//from w ww . ja va2 s . c om JFreeChart chart = ChartFactory.createBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // orientation false, // include legend true, // tooltips? false // URLs? ); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // set the background color for the chart... chart.setBackgroundPaint(color); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setUpperMargin(0.10); rangeAxis.setNumberFormatOverride(nf); if (firstAxisLB != null && firstAxisUB != null) { rangeAxis.setLowerBound(firstAxisLB); rangeAxis.setUpperBound(firstAxisUB); } if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } else rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // add CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}"); renderer.setLegendItemLabelGenerator(generator); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } if (showValueLabels) { renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); // if(valueLabelsPosition.equalsIgnoreCase("inside")){ // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // } else { // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // } } // PROVA LEGENDA if (legend == true) { drawLegend(chart); /*BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); LabelBlock titleBlock = new LabelBlock("Legend Items:", new Font("SansSerif", Font.BOLD, 12)); title.setPadding(5, 5, 5, 5); wrapper.add(titleBlock, RectangleEdge.TOP); LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer items = legend.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend.setWrapper(wrapper); if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM); else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT); else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT); else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP); else legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend);*/ } int seriesN = dataset.getRowCount(); // the order color vedctor overrides the color map!! if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { logger.debug("color serie by SERIES_COLORS template specification"); for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serieName; serieName = (String) seriesCaptions.get(serieName); index = dataset.getRowIndex(labelName); } else index = dataset.getRowIndex(serieName); Color color = (Color) colorMap.get(serieName); if (color != null) { //renderer.setSeriesPaint(i, color); renderer.setSeriesPaint(index, color); renderer.setSeriesItemLabelFont(i, new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor()); } } } CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); domainAxis.setUpperMargin(0.10); logger.debug("OUT"); return chart; }
From source file:playground.christoph.evacuation.analysis.AgentsInMunicipalityEventsHandler.java
private JFreeChart getGraphic() { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries insideSerie = new XYSeries("total inside area", false, true); final XYSeries residentsSerie = new XYSeries("residents inside area", false, true); final XYSeries commutersSerie = new XYSeries("commuters inside area", false, true); for (int i = 0; i < plotData.size(); i++) { PlotData pd = plotData.get(i);// w w w . jav a2 s.co m double hour = pd.time / 3600.0; insideSerie.add(hour, pd.commuterAgentCount + pd.residentAgentCount); residentsSerie.add(hour, pd.residentAgentCount); commutersSerie.add(hour, pd.commuterAgentCount); } xyData.addSeries(insideSerie); xyData.addSeries(residentsSerie); xyData.addSeries(commutersSerie); final JFreeChart chart = ChartFactory.createXYStepChart("agents inside area", "time [hour]", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); NumberAxis na = new NumberAxis("time [hour]"); na.setRange(0, maxTime / 3600.0); na.setLabelFont(plot.getRangeAxis().getLabelFont()); na.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); plot.setDomainAxis(na); return chart; }
From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java
private JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createBarChart( ResourceBundleHelper.getMessageString("overview.traceoverview.title"), null, null, createDataset(), PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis valueRangeAxis = plot.getDomainAxis(); valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f); valueRangeAxis.setMaximumCategoryLabelLines(2); valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT); valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentile")); rangeAxis.setRange(0.0, 100.0);//from w w w . j a v a 2 s . co m rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String traceInfo = ""; switch (arg2) { case TRACE_AVERAGE: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.avg"); break; case TRACE_ENERGY: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.engy"); break; case TRACE_OVERHEAD: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.ovrhd"); break; default: break; } return traceInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); return chart; }
From source file:com.att.aro.ui.view.overviewtab.ConnectionStatisticsChartPanel.java
public JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createBarChart( ResourceBundleHelper.getMessageString("overview.sessionoverview.title"), null, null, createDataset(), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0);/* ww w. j a v a 2 s . c o m*/ rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionLongBurst"); break; default: break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); return chart; }
From source file:charts.Chart.java
public static void GraficoSeries() { //System.out.println("After initComponents"); JFrame janela = new JFrame("Example of the series graphic"); janela.getContentPane().setLayout(null); javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); jLabel1.setText(""); janela.getContentPane().add(jLabel1); y_of_x = new double[n_points]; x = new double[n_points]; XYSeries series1 = new XYSeries("Cos(x) versus x"); XYSeries series2 = new XYSeries("Cos^2(x) versus x"); for (int i = 0; i < n_points; i++) {//calculate the data to be plotted y_of_x[i] = Math.cos(i * Math.PI / 180); series1.add((double) i, y_of_x[i]);//add values to the series series2.add((double) i, Math.pow(y_of_x[i], 2)); }//from w w w. j av a 2s . c o m XYDataset dataset1 = new XYSeriesCollection(series1); XYDataset dataset2 = new XYSeriesCollection(series2); CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis("x-angle argument")); XYItemRenderer renderer1 = new StandardXYItemRenderer(); XYPlot subplot1 = new XYPlot(dataset1, null, new NumberAxis("Cos(x)"), renderer1); NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis(); axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis1.setAutoRangeIncludesZero(false); parent.add(subplot1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); XYPlot subplot2 = new XYPlot(dataset2, null, new NumberAxis("Cos^2(x)"), renderer2); NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis(); axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis2.setAutoRangeIncludesZero(false); parent.add(subplot2, 1); JFreeChart chart = new JFreeChart("Cos(x) versus x", parent); ChartPanel myChart = new ChartPanel(chart); janela.setSize(500, 600); janela.setContentPane(myChart); janela.setVisible(true); }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void updateChart(SimpleFeatureCollection features, String field) { int bin = spinner.getSelection(); double[] values = getValues(features, field); HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(field, values, bin, minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); dataset.setType(histogramType);/*from w w w .j a v a 2 s. c om*/ JFreeChart chart = ChartFactory.createHistogram(EMPTY, null, null, dataset, PlotOrientation.VERTICAL, false, false, false); // 1. Create a single plot containing both the scatter and line chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.85F); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis valueAxis = new NumberAxis(cboField.getText()); valueAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); valueAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); valueAxis.setAutoRange(false); valueAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); String rangeAxisLabel = histogramType == HistogramType.FREQUENCY ? "Frequency" : "Ratio"; //$NON-NLS-1$ //$NON-NLS-2$ NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); rangeAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); if (histogramType == HistogramType.FREQUENCY) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); CustomXYBarPainter.selectedColumn = -1; // init renderer.setBarPainter(new CustomXYBarPainter()); renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesPaint(true); renderer.setShadowXOffset(3); renderer.setMargin(0.01); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER); renderer.setBasePositiveItemLabelPosition(pos); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); renderer.setBaseToolTipGenerator(plotToolTip); // color GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, java.awt.Color.GRAY, 0.0f, 0.0f, java.awt.Color.LIGHT_GRAY); renderer.setSeriesPaint(0, gp0); plot.setDomainAxis(0, valueAxis); plot.setRangeAxis(0, rangeAxis); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.RED); lineRenderer.setSeriesStroke(0, new BasicStroke(2f)); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); xLineAxis.setAutoRange(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); yLineAxis.setAutoRange(false); double maxYValue = Double.MIN_VALUE; for (int i = 0; i < dataset.getItemCount(0); i++) { maxYValue = Math.max(maxYValue, dataset.getYValue(0, i)); } XYSeriesCollection lineDatset = new XYSeriesCollection(); // Vertical Average XYSeries vertical = new XYSeries("Average"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), 0); vertical.add(minMaxVisitor.getAverageX(), maxYValue); lineDatset.addSeries(vertical); plot.setDataset(1, lineDatset); 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); chartComposite.setChart(chart); chartComposite.forceRedraw(); }