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; }
/** * Problem equals method. */ public void testEquals() { CategoryLabelPositions p1 = new CategoryLabelPositions( new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER) ); CategoryLabelPositions p2 = new CategoryLabelPositions( new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.CENTER) ); assertEquals(p1, p2); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { CategoryLabelPositions p1 = new CategoryLabelPositions( new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER) ); CategoryLabelPositions p2 = new CategoryLabelPositions( new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER) ); assertTrue(p1.equals(p2)); int h1 = p1.hashCode(); int h2 = p2.hashCode(); assertEquals(h1, h2); }
/** * Test results chart. * * @param stats SortedMap with dates as keys and * TestStatistics as value. * @param categoryLabel - label to place on X axis. * @param out OutputStream to write image to. */ public static void createTestResultsChart(final SortedMap stats, final String categoryLabel, final String dateFormat, final OutputStream out) throws IOException { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry) iter.next(); final Date date = (Date) entry.getKey(); final TestStatistics tst = (TestStatistics) entry.getValue(); if (tst.getTotalTests() == 0) continue; // skip no-test values final String dateAsString = StringUtils.formatDate(date, dateFormat); dataset.addValue(new Integer(tst.getAverageFailedTests()), CAPTION_FAILED_TESTS, dateAsString); dataset.addValue(new Integer(tst.getAverageErrorTests()), CAPTION_ERROR_TESTS, dateAsString); dataset.addValue(new Integer(tst.getAverageSuccessfulTests()), CAPTION_SUCCESSFUL_TESTS, dateAsString); } // create the chart object createTestsResultsChartHelper(categoryLabel, dataset, out, CategoryLabelPositions.UP_45); }
/** * Test results chart. * * @param stats SortedMap with dates as keys and * TestStatistics as value. * @param categoryLabel - label to place on X axis. * @param out OutputStream to write image to. */ public static void createTestResultsChart(final SortedMap stats, final String categoryLabel, final OutputStream out) throws IOException { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry) iter.next(); final String buildNumberAsString = entry.getKey().toString(); final TestStatistics tst = (TestStatistics) entry.getValue(); final Integer failed = new Integer(tst.getFailedTests()); final Integer error = new Integer(tst.getErrorTests()); final Integer successful = new Integer(tst.getSuccessfulTests()); dataset.addValue(failed, CAPTION_FAILED_TESTS, buildNumberAsString); dataset.addValue(error, CAPTION_ERROR_TESTS, buildNumberAsString); dataset.addValue(successful, CAPTION_SUCCESSFUL_TESTS, buildNumberAsString); } // create the chart object createTestsResultsChartHelper(categoryLabel, dataset, out, CategoryLabelPositions.UP_45); }
@Override public JFreeChart getJFreeChart( String name, PlotOrientation orientation, CategoryLabelPositions labelPositions, Map<String, Double> categoryValues ) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for ( Entry<String, Double> entry : categoryValues.entrySet() ) { dataSet.addValue( entry.getValue(), name, entry.getKey() ); } CategoryPlot plot = getCategoryPlot( dataSet, getBarRenderer(), orientation, labelPositions ); JFreeChart jFreeChart = getBasicJFreeChart( plot ); jFreeChart.setTitle( name ); return jFreeChart; }
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; }
private JFreeChart getStackedBarChart( BaseChart chart, CategoryDataset dataSet, boolean horizontal ) { JFreeChart stackedBarChart = ChartFactory.createStackedBarChart( chart.getName(), chart.getDomainAxisLabel(), chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !chart.isHideLegend(), false, false ); setBasicConfig( stackedBarChart, chart ); 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; }
@Override public JFreeChart getOrganisationUnitDistributionChart( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit ) { Map<String, Double> categoryValues = new HashMap<>(); Grid grid = getOrganisationUnitDistribution( groupSet, organisationUnit, true ); if ( grid == null || grid.getHeight() != 1 ) { return null; } for ( int i = 1; i < grid.getWidth() - 2; i++ ) // Skip name, none and total column { categoryValues.put( grid.getHeaders().get( i ).getName(), Double.valueOf( String.valueOf( grid.getRow( 0 ).get( i ) ) ) ); } String title = groupSet.getName() + TITLE_SEP + organisationUnit.getName(); JFreeChart chart = chartService.getJFreeChart( title, PlotOrientation.VERTICAL, CategoryLabelPositions.DOWN_45, categoryValues ); return chart; }
@Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset, PlotOrientation.VERTICAL, true, true, true); chart.setBackgroundPaint(Color.WHITE); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); plot.setDomainAxis(domainAxis); plot.setBackgroundPaint(Color.WHITE); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //yAxis.setRange(0.0, 100.0); URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject()); ColorPalette.apply(urlRenderer); plot.setRenderer(urlRenderer); return chart; }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { CategoryLabelPositions p1 = new CategoryLabelPositions( new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER)); CategoryLabelPositions p2 = new CategoryLabelPositions( new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER), new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER)); assertTrue(p1.equals(p2)); int h1 = p1.hashCode(); int h2 = p2.hashCode(); assertEquals(h1, h2); }
/** Configures display of domain and range axes */ private void configureAxes(CategoryPlot plot) { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(includeZero); if (integerRange) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } rangeAxis.setUpperMargin(0.15); rangeAxis.setVisible(rangeAxisVisible); CategoryAxis domainAxis = plot.getDomainAxis(); if (orientation == EPlotOrientation.HORIZONTAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.STANDARD); domainAxis.setMaximumCategoryLabelWidthRatio(.5f); } else { domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } domainAxis.setVisible(domainAxisVisible); }
public Drawable createChart(ADCDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart( dataset.get(Attribute.TITLE), dataset.get(Attribute.X_AXIS_LABEL), dataset.get(Attribute.Y_AXIS_LABEL), dataset, PlotOrientation.VERTICAL, true, false, false); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis raxis = plot.getRangeAxis(); raxis.setRange(0, 100.0); CategoryAxis cAxis = plot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); BarRenderer renderer = (BarRenderer)plot.getRenderer(); renderer.setSeriesPaint(0, Colors.fromHex("#0AA1D8")); renderer.setSeriesPaint(1, Colors.fromHex("#932832")); renderer.setSeriesPaint(2, Colors.fromHex("#94BA4D")); renderer.setBarPainter(new StandardBarPainter()); renderer.setItemMargin(0.01); return new JFreeChartDrawable(chart, new Dimension(750, 500)); }
public static Drawable createChart(ADCDataset dataset, Dimension dimension) { final JFreeChart chart = ChartFactory.createBarChart( dataset.get(Attribute.TITLE),// chart title dataset.get(Attribute.X_AXIS_LABEL),// domain axis label dataset.get(Attribute.Y_AXIS_LABEL),// range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final BarRenderer renderer = (BarRenderer)plot.getRenderer(); Colors.setSeriesPaint(renderer, dataset.get(Attribute.SERIES_COLORS)); renderer.setItemMargin(0); renderer.setBarPainter(new StandardBarPainter()); final CategoryAxis cAxis = plot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.getTitle().setFont(cAxis.getLabelFont()); chart.getLegend().setMargin(2, 60, 2, 20); return new JFreeChartDrawable(chart, dimension); }
public static Drawable createChart(final ADSCDataset dataset, ChartType type, Region region, Dimension dimension) { JFreeChart chart; if(region == Region.GBR) { chart = createChart(rearrange(dataset), type); CategoryPlot plot = (CategoryPlot)chart.getPlot(); CategoryAxis cAxis = getSubCategoryAxis(dataset); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); cAxis.setLabelFont(plot.getRangeAxis().getLabelFont()); cAxis.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); cAxis.setTickMarksVisible(false); cAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL)); plot.setDomainAxis(cAxis); } else { chart = createChart(dataset, type); } return new JFreeChartDrawable(chart, dimension); }
public static Drawable createChart(ADCDataset dataset, Dimension dimension) { final JFreeChart chart = ChartFactory.createBarChart( dataset.get(Attribute.TITLE), // chart title dataset.get(Attribute.X_AXIS_LABEL), // domain axis label dataset.get(Attribute.Y_AXIS_LABEL),// range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final BarRenderer renderer = (BarRenderer)plot.getRenderer(); Colors.setSeriesPaint(renderer, dataset.get(Attribute.SERIES_COLORS)); renderer.setItemMargin(0); renderer.setBarPainter(new StandardBarPainter()); final CategoryAxis cAxis = plot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); return new JFreeChartDrawable(chart, dimension); }
private JFreeChart createChart() { JFreeChart chart = ChartFactory.createBarChart( "Top 20 Download Rates", "Remote IP", "KB/s", createDataset(), PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0) ); return chart; }
private JFreeChart createChart() { JFreeChart chart = ChartFactory.createStackedBarChart( "Top 20 Block Peers", "Remote IP", "Blocks", createDataset(), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0) ); return chart; }
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; }
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); }
/** * It creates a chart for the given dataset and adds the chart to the panel. * * @param dataset The dataset that will provide the values for the chart. */ private void addChart() { JFreeChart chart = ChartFactory.createStackedBarChart3D( getTitle(), null, "Breakdown" + unitSuffix(), dataset, PlotOrientation.VERTICAL, true, true, false); CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chart.addProgressListener(locker); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator(dataset); mainPanel().add(BorderLayout.CENTER, new ChartPanel(chart)); }
/** * 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)); }
/** * Creates a chart for recent time to fix. * */ public void createChart(final SortedMap time, final String valueKey, final Color lineColor, final OutputStream out) throws IOException { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); addTimeToDataSet(dataset, time, valueKey); // create the chart object // This generates a stacked bar - more suitable final JFreeChart chart = ChartFactory.createLineChart(null, "Recent builds", "Time", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); // change the auto tick unit selection to integer units only final CategoryPlot plot = chart.getCategoryPlot(); final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(StatisticsUtils.createWordedTimeTickUnits()); // rotate X dates final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set bar colors final LineAndShapeRenderer line = (LineAndShapeRenderer)plot.getRenderer(); line.setSeriesPaint(0, lineColor); line.setStroke(StatisticsUtils.DEFAULT_LINE_STROKE); // write to reposnce final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.writeChartAsPNG(out, chart, StatisticsUtils.IMG_WIDTH, StatisticsUtils.IMG_HEIGHT, info); }
public void createChart(final SortedMap stats, final OutputStream out) throws IOException { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry)iter.next(); final Integer buildNumber = (Integer)entry.getKey(); final Integer violations = (Integer)entry.getValue(); dataset.addValue(violations, categoryDescription, buildNumber); } // create the chart object // This generates a stacked bar - more suitable final JFreeChart chart = ChartFactory.createLineChart(null, "Recent builds", valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); // change the auto tick unit selection to integer units only final CategoryPlot plot = chart.getCategoryPlot(); final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // rotate X dates final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set bar colors final LineAndShapeRenderer line = (LineAndShapeRenderer)plot.getRenderer(); line.setSeriesPaint(0, Color.RED); line.setStroke(StatisticsUtils.DEFAULT_LINE_STROKE); // write to reposnce final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.writeChartAsPNG(out, chart, StatisticsUtils.IMG_WIDTH, StatisticsUtils.IMG_HEIGHT, info); }
/** * */ private static void createTestsResultsChartHelper(final String categoryLabel, final DefaultCategoryDataset dataset, final OutputStream out, final CategoryLabelPositions categoryLabelPosition) throws IOException { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, categoryLabel, "Tests", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); // change the auto tick unit selection to integer units only final CategoryPlot plot = chart.getCategoryPlot(); final LogarithmicAxis logarithmicAxis = new LogarithmicAxis("Tests"); logarithmicAxis.setStrictValuesFlag(false); logarithmicAxis.setAutoRangeIncludesZero(true); logarithmicAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(logarithmicAxis); // final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); // rotate X dates final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(categoryLabelPosition); // set area colors final StackedAreaRenderer area = (StackedAreaRenderer) plot.getRenderer(); area.setSeriesPaint(0, Color.RED); // first area area.setSeriesPaint(1, Color.PINK); // second area area.setSeriesPaint(2, Color.GREEN); // thirs area //plot.setRenderer(area); // write to reposnce final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info); }
public static void createRecentBuildTimesChart(final SortedMap stats, final String categoryLabel, final OutputStream out) throws IOException { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry) iter.next(); final Integer buildNumber = (Integer) entry.getKey(); final Integer timeInSeconds = (Integer) entry.getValue(); dataset.addValue(timeInSeconds, "Build time", buildNumber); } // create the chart object // This generates a stacked bar - more suitable final JFreeChart chart = ChartFactory.createLineChart(null, categoryLabel, "Build time", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); // change the auto tick unit selection to integer units only final CategoryPlot plot = chart.getCategoryPlot(); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setStandardTickUnits(createWordedTimeTickUnits()); // rotate X dates final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set bar colors final LineAndShapeRenderer line = (LineAndShapeRenderer) plot.getRenderer(); line.setSeriesPaint(0, Color.BLUE); line.setStroke(DEFAULT_LINE_STROKE); // write to reposnce final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info); }
/** * Creates a new demo instance. * * @param title the frame title. */ public TestBarChart( final String title ) { super( title ); final CategoryDataset dataset1 = createData(); // create the chart... final JFreeChart chart = ChartFactory.createBarChart( "Bunny Statistics", // chart title "Trait", // domain axis label "Population", // range axis label dataset1, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URL generator? Not required... ); final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 4.0 ) ); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel( chart ); chartPanel.setPreferredSize( new java.awt.Dimension( 500, 270 ) ); setContentPane( chartPanel ); }
public frmFeatureSelection(Dataset ds) { initComponents(); pb.setVisible(false); graphDS = new DefaultCategoryDataset(); workers = new ArrayList<>(); this.ds = ds; chart = ChartFactory.createLineChart( "Distribution of correlation between profile couples", // chart title "Correlation", // domain axis label "Normalized frequency", // range axis label graphDS, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chartPane = new ChartPanel(chart, true, true, true, true, true) { @Override public void paintComponent(Graphics g) { //g.setClip(this.getBorder().); super.paintComponent(g); } }; chart.setBackgroundPaint(new Color(255, 255, 255)); chartPane.setBackground(new Color(255, 255, 255)); chartPane.setOpaque(true); chartPane.setBorder(new GlassBorder()); chartPane.setInitialDelay(10); jSplitPane1.setRightComponent(chartPane); chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); chart.getCategoryPlot().getDomainAxis().setMaximumCategoryLabelWidthRatio(0.5f); }
protected void handleCategoryPlotSettings(CategoryPlot p, JRChartPlot jrPlot) { Double defaultPlotLabelRotation = (Double)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_LABEL_ROTATION); PlotOrientation defaultPlotOrientation = (PlotOrientation)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_ORIENTATION); // Handle rotation of the category labels. CategoryAxis axis = p.getDomainAxis(); boolean hasRotation = jrPlot.getLabelRotationDouble() != null || defaultPlotLabelRotation != null; if(hasRotation) { double labelRotation = jrPlot.getLabelRotationDouble() != null ? jrPlot.getLabelRotationDouble().doubleValue() : defaultPlotLabelRotation.doubleValue(); if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( (-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); } } if (defaultPlotOrientation != null) { p.setOrientation(defaultPlotOrientation); } }
/** * Returns a CategoryPlot. */ private CategoryPlot getCategoryPlot( CategoryDataset dataSet, CategoryItemRenderer renderer, PlotOrientation orientation, CategoryLabelPositions labelPositions ) { CategoryPlot plot = new CategoryPlot( dataSet, new CategoryAxis(), new NumberAxis(), renderer ); plot.setDatasetRenderingOrder( DatasetRenderingOrder.FORWARD ); plot.setOrientation( orientation ); CategoryAxis xAxis = plot.getDomainAxis(); xAxis.setCategoryLabelPositions( labelPositions ); return plot; }
/** * Render a histogram chart from summary data (i.e. a list of bin labels and * corresponding frequencies) to a buffered image * * @param width the width of the resulting image * @param height the height of the resulting image * @param bins the list of bin labels * @param freqs the corresponding bin frequencies * @param additionalArgs optional arguments to the renderer (may be null) * @return a histogram as a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderHistogramFromSummaryData(int width, int height, List<String> bins, List<Double> freqs, List<String> additionalArgs) throws Exception { JFreeChart chart = getHistogramFromSummaryDataChart(bins, freqs, additionalArgs); CategoryAxis axis = chart.getCategoryPlot().getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); Font newFont = new Font("SansSerif", Font.PLAIN, 11); axis.setTickLabelFont(newFont); BufferedImage image = chart.createBufferedImage(width, height); return image; }
/** * This method sets the x-axis labels in a rotated position. Use this only if there are a lot of bars in the graph, so there is very limited space * for eacht label on the x-axis. By rotating the labels, they wont overlap each other, and there will be more space per label. Set this in the * jsp via the param tag, using the keyword "xlabelRotation": <cewolf:chartpostprocessor id="chartPostProcessorImpl" > <cewolf:param * name="xlabelRotation" value="<%= new Double(0.60)%>"/> </cewolf:chartpostprocessor> The parameter is a double, indicating the rotation angle in * radials. <b>NOTE:</b> the rotation is set to 0.60 by default if the number of categories > 14; otherwise, the default rotation is 0. Setting * the parameter overrides this default. * @param plot * @param params */ @SuppressWarnings("rawtypes") private void setRotatedXaxisLabels(final CategoryPlot plot, final Map params) { Double rotation = (Double) params.get("xlabelRotation"); final int numberOfCategories = plot.getCategories().size(); if (rotation == null && numberOfCategories > ROTATE_XLABELS_IF_MORE_THAN) { rotation = new Double(0.60); } if (rotation != null && rotation != 0) { final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(rotation.doubleValue())); } }