Java Code Examples for org.jfree.chart.plot.CategoryPlot#getDomainAxis()

The following examples show how to use org.jfree.chart.plot.CategoryPlot#getDomainAxis() . 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: CommonBarChartAction.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
private void fillChart(String title, String categoryLabel, String valueLabel, 
		List<String> names, List<Float> values, List<String> colors, boolean horizontal) throws Exception {
	DefaultCategoryDataset data=new DefaultCategoryDataset();
	for (int ix=0; ix<names.size(); ix++) {			
		data.addValue(values.get(ix), "", names.get(ix));			
	}		
       this.chart=ChartFactory.createBarChart3D(
       		title, // title
       		categoryLabel,
       		valueLabel, 
       		data, 
       		( horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL ),
       		false,
       		false, 
       		false);		
       CategoryPlot plot=(CategoryPlot)this.chart.getPlot();
       CategoryAxis categoryAxis=plot.getDomainAxis();   
       categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9) );
       categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9) );
       NumberAxis numberAxis=(NumberAxis)plot.getRangeAxis();
       numberAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9) );
       this.setPlotColor(plot, names, colors);
       this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9) ) );		
}
 
Example 2
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 3
Source File: ScheduleReport.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: CategoryBoxplot.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: CategoryHistogram.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public JFreeChart getChart() {
    if (chart == null) {
        createDataset();
        chart = ChartFactory.createBarChart(title,
        // chart title
                xLabel,
                // domain axis label
                yLabel,
                // 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);
    }
    return chart;
}
 
Example 6
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private byte[] generateBoxAndWhiskerChart (BoxAndWhiskerCategoryDataset dataset, int width, int height)
{
	JFreeChart chart = ChartFactory.createBoxAndWhiskerChart (null, null,
			null, dataset, false);

	// 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 ();

	plot.setDomainGridlinePaint (Color.white);
	plot.setDomainGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);

	NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis ();
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());

	CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis ();
	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 7
Source File: SWTBarChartDemo1.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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 8
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
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 9
Source File: ParetoChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
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 10
Source File: SWTBarChartDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 11
Source File: AggregationExecutionChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
@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: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
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 13
Source File: SWTBarChartDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a sample chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(
        "Bar Chart Demo",         // 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...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    );
    // OPTIONAL CUSTOMISATION COMPLETED.
    
    return chart;
    
}
 
Example 14
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
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 15
Source File: SWTBarChartDemo1.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 16
Source File: AbstractCategoryItemRenderer.java    From buffer_bci with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns a domain axis for a plot.
 *
 * @param plot  the plot.
 * @param index  the axis index.
 *
 * @return A domain axis.
 */
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
    CategoryAxis result = plot.getDomainAxis(index);
    if (result == null) {
        result = plot.getDomainAxis();
    }
    return result;
}
 
Example 17
Source File: AbstractCategoryItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a domain axis for a plot.
 *
 * @param plot  the plot.
 * @param index  the axis index.
 *
 * @return A domain axis.
 */
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
    CategoryAxis result = plot.getDomainAxis(index);
    if (result == null) {
        result = plot.getDomainAxis();
    }
    return result;
}
 
Example 18
Source File: AbstractCategoryItemRenderer.java    From ccu-historian with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns a domain axis for a plot.
 *
 * @param plot  the plot.
 * @param index  the axis index.
 *
 * @return A domain axis.
 */
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
    CategoryAxis result = plot.getDomainAxis(index);
    if (result == null) {
        result = plot.getDomainAxis();
    }
    return result;
}
 
Example 19
Source File: AbstractCategoryItemRenderer.java    From opensim-gui with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a domain axis for a plot.
 * 
 * @param plot  the plot.
 * @param index  the axis index.
 * 
 * @return A domain axis.
 */
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
    CategoryAxis result = plot.getDomainAxis(index);
    if (result == null) {
        result = plot.getDomainAxis();
    }
    return result;
}
 
Example 20
Source File: AbstractCategoryItemRenderer.java    From buffer_bci with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns a domain axis for a plot.
 *
 * @param plot  the plot.
 * @param index  the axis index.
 *
 * @return A domain axis.
 */
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
    CategoryAxis result = plot.getDomainAxis(index);
    if (result == null) {
        result = plot.getDomainAxis();
    }
    return result;
}