org.jfree.chart.axis.CategoryLabelPositions Java Examples

The following examples show how to use org.jfree.chart.axis.CategoryLabelPositions. 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: 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 #2
Source File: ChartAxisFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #3
Source File: ExpressionProfile.java    From chipster with MIT License 6 votes vote down vote up
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 #4
Source File: CategoryLabelPositionsTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
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 #6
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JFreeChart getStackedAreaChart( final Visualization visualization, CategoryDataset dataSet )
{
    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart( visualization.getName(), visualization.getDomainAxisLabel(),
        visualization.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !visualization.isHideLegend(), false, false );

    setBasicConfig( stackedAreaChart, visualization );

    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 #7
Source File: StatisticalBarChartBuilder.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset,
        PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
{
    CategoryAxis xAxis = new CategoryAxis(xAxisTitle);
    ValueAxis yAxis = new NumberAxis(yAxisTitle);
    CategoryItemRenderer renderer = new StatisticalBarRenderer();

    CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true);

    chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}
 
Example #8
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #9
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #10
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@Transactional( readOnly = true )
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;
}
 
Example #11
Source File: CategoryLabelPositionsTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: AWSDeviceFarmGraph.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
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() :
				defaultPlotLabelRotation;
		
		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);
	}
}
 
Example #15
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 #16
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 #17
Source File: CategoryDataSetBasedChartBuilder.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
protected final JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
{
    JFreeChart chart = createCategoryChart(title, xAxisTitle, yAxisTitle, dataset, plotOrientation, showLegend, showToolTips, showUrls);
    chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    return chart;
}
 
Example #18
Source File: RoboTaxiRequestHistoGramExport.java    From amod with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void summaryTarget(AnalysisSummary analysisSummary, File relativeDirectory, ColorDataIndexed colorScheme) {
    /** the data for the histogram is gathered from the RoboTaxiRequestRecorder, basic
     * information can also be retrieved from the analsysisSummary */
    Tensor requestsPerRoboTaxi = roboTaxiRequestRecorder.getRequestsPerRoboTaxi();
    Scalar numberOfRoboTaxis = RealScalar.of(requestsPerRoboTaxi.length());
    Scalar totalRequestsServed = (Scalar) Total.of(requestsPerRoboTaxi);
    Scalar histoGrambinSize = Scalars.lessThan(RealScalar.ZERO, totalRequestsServed) ? //
            totalRequestsServed.divide(numberOfRoboTaxis.multiply(RealScalar.of(10))) : RealScalar.ONE;

    try {
        /** compute bins */
        Scalar numValues = RationalScalar.of(requestsPerRoboTaxi.length(), 1);
        Tensor bins = BinCounts.of(requestsPerRoboTaxi, histoGrambinSize);
        bins = bins.divide(numValues).multiply(RealScalar.of(100)); // norm

        VisualSet visualSet = new VisualSet(colorScheme);
        visualSet.add(Range.of(0, bins.length()).multiply(histoGrambinSize), bins);
        // ---
        visualSet.setPlotLabel("Number of Requests Served per RoboTaxi");
        visualSet.setAxesLabelY("% of RoboTaxis");
        visualSet.setAxesLabelX("Requests");

        JFreeChart jFreeChart = Histogram.of(visualSet, s -> "[" + s.number() + " , " + s.add(histoGrambinSize).number() + ")");
        CategoryPlot categoryPlot = jFreeChart.getCategoryPlot();
        categoryPlot.getDomainAxis().setLowerMargin(0.0);
        categoryPlot.getDomainAxis().setUpperMargin(0.0);
        categoryPlot.getDomainAxis().setCategoryMargin(0.0);
        categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.START);

        File file = new File(relativeDirectory, FILENAME);
        AmodeusChartUtils.saveAsPNG(jFreeChart, file.toString(), WIDTH, HEIGHT);
        GlobalAssert.that(file.isFile());
    } catch (Exception exception) {
        System.err.println("Plot of the Number of Requests per RoboTaxi Failed");
        exception.printStackTrace();
    }
}
 
Example #19
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 #20
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 #21
Source File: SWTBarChartDemo1.java    From ECG-Viewer 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 #22
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 #23
Source File: CategoryAxisTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 #24
Source File: SWTBarChartDemo1.java    From buffer_bci 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 #25
Source File: BarChartDemo1.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) {

    JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1",
            "Category", "Value", dataset, true);                   
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

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

    // 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 = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(
                    Math.PI / 6.0));

    return chart;

}
 
Example #26
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 #27
Source File: BarChartDemo1.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 1",       // 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);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************
    
    // 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);
    
    // 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 = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(
                    Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    
    return chart;
    
}
 
Example #28
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 #29
Source File: CategoryAxisTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 #30
Source File: BarChartDemo1.java    From opensim-gui 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(
        "Bar Chart Demo 1",       // 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 = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************
    
    // 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);
    
    // 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 = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(
                    Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    
    return chart;
    
}