Java Code Examples for org.jfree.chart.axis.CategoryAxis#setCategoryLabelPositions()
The following examples show how to use
org.jfree.chart.axis.CategoryAxis#setCategoryLabelPositions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartAxisFactory.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
public static CategoryAxis createCategoryDomainAxis(PlotConfiguration plotConfiguration) { CategoryAxis domainAxis = new CategoryAxis(null); String label = plotConfiguration.getDomainConfigManager().getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); } domainAxis.setLabel(label); Font axesFont = plotConfiguration.getAxesFont(); if (axesFont != null) { domainAxis.setLabelFont(axesFont); domainAxis.setTickLabelFont(axesFont); } // rotate labels if (plotConfiguration.getOrientation() != PlotOrientation.HORIZONTAL) { domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } formatAxis(plotConfiguration, domainAxis); return domainAxis; }
Example 2
Source File: ScheduleReport.java From ezScrum with GNU General Public License v2.0 | 6 votes |
private void setAttribute(JFreeChart chart) { // 圖案與文字的間隔 LegendTitle legend = chart.getLegend(); legend.setBorder(1, 1, 1, 1); CategoryPlot plot = chart.getCategoryPlot(); // 設定WorkItem的屬性 CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); // 字體角度 domainAxis.setTickLabelFont(new Font("新細明體", Font.TRUETYPE_FONT, 12)); // 字體 // 設定Date的屬性 DateAxis da = (DateAxis) plot.getRangeAxis(0); setDateAxis(da); // 設定實體的顯示名稱 CategoryItemRenderer render = plot.getRenderer(0); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); CategoryItemLabelGenerator generator = new IntervalCategoryItemLabelGenerator( "{3} ~ {4}", format); render.setBaseItemLabelGenerator(generator); render.setBaseItemLabelPaint(Color.BLUE); render.setBaseItemLabelsVisible(true); render.setBaseItemLabelFont(new Font("黑體", Font.TRUETYPE_FONT, 8)); render.setSeriesPaint(0, Color.RED); }
Example 3
Source File: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private JFreeChart getStackedAreaChart( BaseChart chart, CategoryDataset dataSet ) { JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart( chart.getName(), chart.getDomainAxisLabel(), chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !chart.isHideLegend(), false, false ); setBasicConfig( stackedAreaChart, chart ); CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot(); plot.setOrientation( PlotOrientation.VERTICAL ); plot.setRenderer( getStackedAreaRenderer() ); CategoryAxis xAxis = plot.getDomainAxis(); xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 ); xAxis.setLabelFont( LABEL_FONT ); return stackedAreaChart; }
Example 4
Source File: ChartImageGenerator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private JFreeChart getStackedBarChart( final Visualization visualization, CategoryDataset dataSet, boolean horizontal ) { JFreeChart stackedBarChart = ChartFactory.createStackedBarChart( visualization.getName(), visualization.getDomainAxisLabel(), visualization.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !visualization.isHideLegend(), false, false ); setBasicConfig( stackedBarChart, visualization ); CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot(); plot.setOrientation( horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL ); plot.setRenderer( getStackedBarRenderer() ); CategoryAxis xAxis = plot.getDomainAxis(); xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 ); return stackedBarChart; }
Example 5
Source File: ExpressionProfile.java From chipster with MIT License | 6 votes |
public JFreeChart createProfileChart(CategoryDataset categoryDataset, List<ProfileRow> rows, String name) throws MicroarrayException { // draw plot CategoryAxis categoryAxis = new CategoryAxis("sample"); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryAxis.setUpperMargin(0.0); categoryAxis.setLowerMargin(0.0); ValueAxis valueAxis = new NumberAxis("expression"); plot = new CategoryPlot(categoryDataset, categoryAxis, valueAxis, createRenderer(rows)); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Expression profile for " + name, JFreeChart.DEFAULT_TITLE_FONT, plot, false); return chart; }
Example 6
Source File: CategoryBoxplot.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public JFreeChart getChart() { if (chart == null) { createDataset(); chart = ChartFactory.createBarChart(getTitle(), // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis rangeAxis = plot.getDomainAxis(); rangeAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // TODO reactivate if newer jfree is used // renderer.setMeanVisible(isMeanVisible); plot.setRenderer(renderer); } return chart; }
Example 7
Source File: AWSDeviceFarmGraph.java From aws-device-farm-jenkins-plugin with Apache License 2.0 | 5 votes |
/** * Create graph based on the given dataset and constraints. * * @return The JFreeChart graph. */ protected JFreeChart createGraph() { // Create chart. JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); // Create chart legend. LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); // Create chart plot. CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.darkGray); // Create domain (x) axis. CategoryAxis domain = new ShiftedCategoryAxis(xLabel); domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setCategoryMargin(0.0); plot.setDomainAxis(domain); // Create range (y) axis. NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRange(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create renderer and paint the chart. CategoryItemRenderer renderer = plot.getRenderer(); plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); // Set chart colors for sections. for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } return chart; }
Example 8
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBarChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer (); renderer.setDrawBarOutline (false); renderer.setSeriesBarWidth (0, .6); renderer.setSeriesBarWidth (1, .8); renderer.setSeriesBarWidth (2, 1.0); plot.setRenderer (renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder (SortOrder.DESCENDING); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint (0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color (0, 0, 64)); GradientPaint gp1 = new GradientPaint (0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color (0, 64, 0)); GradientPaint gp2 = new GradientPaint (0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color (64, 0, 0)); renderer.setSeriesPaint (0, gp0); renderer.setSeriesPaint (1, gp1); renderer.setSeriesPaint (2, gp2); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 9
Source File: UserChartController.java From airsonic-advanced with GNU General Public License v3.0 | 4 votes |
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint( 0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64) ); renderer.setSeriesPaint(0, gp0); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
Example 10
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateStackedAreaChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createStackedAreaChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // set transparency plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (true); plot.setDomainGridlinePaint (Color.white); plot.setRangeGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); // set colour of regular users using Karate belt colour: white, green, blue, brown, black/gold CategoryItemRenderer renderer = plot.getRenderer (); renderer.setSeriesPaint (0, new Color (205, 173, 0)); // gold users renderer.setSeriesPaint (1, new Color (139, 69, 19)); renderer.setSeriesPaint (2, Color.BLUE); renderer.setSeriesPaint (3, Color.GREEN); renderer.setSeriesPaint (4, Color.WHITE); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
Example 11
Source File: AggregationExecutionChartBuilder.java From livingdoc-confluence with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void customizeChart(JFreeChart chart) throws IOException { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = ( CategoryPlot ) chart.getPlot(); plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata")); StackedBarRenderer renderer = new StackedBarRenderer(true); plot.setRenderer(renderer); int index = 0; renderer.setSeriesPaint(index ++ , GREEN_COLOR); if (settings.isShowIgnored()) { renderer.setSeriesPaint(index ++ , Color.yellow); } renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new DefaultTooltipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset data, int series, int category) { Comparable< ? > valueKey = data.getColumnKey(category); ChartLongValue value = ( ChartLongValue ) valueKey; return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0.01); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1.0); if (rangeAxis instanceof NumberAxis) { NumberAxis numberAxis = ( NumberAxis ) rangeAxis; numberAxis.setTickUnit(new NumberTickUnit(.10)); numberAxis.setNumberFormatOverride(PERCENT_FORMATTER); } plot.setForegroundAlpha(0.8f); }
Example 12
Source File: LinearExecutionChartBuilder.java From livingdoc-confluence with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void customizeChart(JFreeChart chart) { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = ( CategoryPlot ) chart.getPlot(); plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata")); CategoryItemRenderer renderer = plot.getRenderer(); int index = 0; renderer.setSeriesPaint(index ++ , GREEN_COLOR); if (settings.isShowIgnored()) { renderer.setSeriesPaint(index ++ , Color.yellow); } renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset data, int series, int category) { Comparable< ? > valueKey = data.getColumnKey(category); ChartLongValue value = ( ChartLongValue ) valueKey; return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); if (rangeAxis instanceof NumberAxis) { ( ( NumberAxis ) rangeAxis ).setTickUnit(new NumberTickUnit(1)); } plot.setForegroundAlpha(0.8f); }
Example 13
Source File: ParetoChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset( "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
Example 14
Source File: SWTBarChartDemo1.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart( "SWTBarChartDemo1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
Example 15
Source File: CategoryAxisTests.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { CategoryAxis a1 = new CategoryAxis("Test"); CategoryAxis a2 = new CategoryAxis("Test"); assertTrue(a1.equals(a2)); // lowerMargin a1.setLowerMargin(0.15); assertFalse(a1.equals(a2)); a2.setLowerMargin(0.15); assertTrue(a1.equals(a2)); // upperMargin a1.setUpperMargin(0.15); assertFalse(a1.equals(a2)); a2.setUpperMargin(0.15); assertTrue(a1.equals(a2)); // categoryMargin a1.setCategoryMargin(0.15); assertFalse(a1.equals(a2)); a2.setCategoryMargin(0.15); assertTrue(a1.equals(a2)); // maxCategoryLabelWidthRatio a1.setMaximumCategoryLabelWidthRatio(0.98f); assertFalse(a1.equals(a2)); a2.setMaximumCategoryLabelWidthRatio(0.98f); assertTrue(a1.equals(a2)); // categoryLabelPositionOffset a1.setCategoryLabelPositionOffset(11); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositionOffset(11); assertTrue(a1.equals(a2)); // categoryLabelPositions a1.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertTrue(a1.equals(a2)); // categoryLabelToolTips a1.addCategoryLabelToolTip("Test", "Check"); assertFalse(a1.equals(a2)); a2.addCategoryLabelToolTip("Test", "Check"); assertTrue(a1.equals(a2)); // tickLabelFont a1.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertFalse(a1.equals(a2)); a2.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertTrue(a1.equals(a2)); // tickLabelPaint a1.setTickLabelPaint("C1", Color.red); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", Color.red); assertTrue(a1.equals(a2)); // tickLabelPaint2 a1.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(a1.equals(a2)); }
Example 16
Source File: SWTBarChartDemo1.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart( "SWTBarChartDemo1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
Example 17
Source File: CategoryAxisTests.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { CategoryAxis a1 = new CategoryAxis("Test"); CategoryAxis a2 = new CategoryAxis("Test"); assertTrue(a1.equals(a2)); // lowerMargin a1.setLowerMargin(0.15); assertFalse(a1.equals(a2)); a2.setLowerMargin(0.15); assertTrue(a1.equals(a2)); // upperMargin a1.setUpperMargin(0.15); assertFalse(a1.equals(a2)); a2.setUpperMargin(0.15); assertTrue(a1.equals(a2)); // categoryMargin a1.setCategoryMargin(0.15); assertFalse(a1.equals(a2)); a2.setCategoryMargin(0.15); assertTrue(a1.equals(a2)); // maxCategoryLabelWidthRatio a1.setMaximumCategoryLabelWidthRatio(0.98f); assertFalse(a1.equals(a2)); a2.setMaximumCategoryLabelWidthRatio(0.98f); assertTrue(a1.equals(a2)); // categoryLabelPositionOffset a1.setCategoryLabelPositionOffset(11); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositionOffset(11); assertTrue(a1.equals(a2)); // categoryLabelPositions a1.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertFalse(a1.equals(a2)); a2.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); assertTrue(a1.equals(a2)); // categoryLabelToolTips a1.addCategoryLabelToolTip("Test", "Check"); assertFalse(a1.equals(a2)); a2.addCategoryLabelToolTip("Test", "Check"); assertTrue(a1.equals(a2)); // tickLabelFont a1.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertFalse(a1.equals(a2)); a2.setTickLabelFont("C1", new Font("Dialog", Font.PLAIN, 21)); assertTrue(a1.equals(a2)); // tickLabelPaint a1.setTickLabelPaint("C1", Color.red); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", Color.red); assertTrue(a1.equals(a2)); // tickLabelPaint2 a1.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(a1.equals(a2)); a2.setTickLabelPaint("C1", new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(a1.equals(a2)); }
Example 18
Source File: SWTBarChartDemo1.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart( "SWTBarChartDemo1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
Example 19
Source File: DerivedCounter.java From mts with GNU General Public License v3.0 | 4 votes |
public JFreeChart getHistogramChart() { double[] hits = this.counter.histogramDataset.getHistogramArray(); double[] intervals = this.counter.histogramDataset.histogramParameters.histogramIntervals; double hitsCount = this.counter.histogramDataset.hits; DefaultCategoryDataset datasetNormal = new DefaultCategoryDataset(); datasetNormal.addValue(0, "a", " -INF"); datasetNormal.addValue(0, "b", " -INF"); double cumul = 0; for (int i = 0; i < intervals.length - 1; i++) { String intervalName; if (i == intervals.length - 2) { intervalName = " +INF"; } else { intervalName = " " + Double.toString(intervals[i + 1]); } cumul += hits[i]; datasetNormal.addValue((100 * hits[i]) / hitsCount, "a", intervalName); datasetNormal.addValue((100 * cumul) / hitsCount, "b", intervalName); } JFreeChart jFreeChart = ChartFactory.createBarChart("", "", "%", datasetNormal, PlotOrientation.VERTICAL, false, false, false); CategoryPlot plot = jFreeChart.getCategoryPlot(); CategoryAxis axis = plot.getDomainAxis(); LayeredBarRenderer layeredBarRenderer = new LayeredBarRenderer(); layeredBarRenderer.setSeriesPaint(0, new Color(0, 0, 255, 85)); layeredBarRenderer.setSeriesPaint(1, new Color(255, 0, 0, 85)); plot.setRenderer(layeredBarRenderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); axis.setMaximumCategoryLabelWidthRatio(1); jFreeChart.setBackgroundPaint(Color.WHITE); return jFreeChart; }
Example 20
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBarChart (null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer (); renderer.setDrawBarOutline (false); renderer.setSeriesBarWidth (0, .6); renderer.setSeriesBarWidth (1, .8); renderer.setSeriesBarWidth (2, 1.0); plot.setRenderer (renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder (SortOrder.DESCENDING); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint (0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color (0, 0, 64)); GradientPaint gp1 = new GradientPaint (0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color (0, 64, 0)); GradientPaint gp2 = new GradientPaint (0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color (64, 0, 0)); renderer.setSeriesPaint (0, gp0); renderer.setSeriesPaint (1, gp1); renderer.setSeriesPaint (2, gp2); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }