Java Code Examples for org.jfree.chart.JFreeChart#getCategoryPlot()

The following examples show how to use org.jfree.chart.JFreeChart#getCategoryPlot() . 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: ChartViewerUtil.java    From cst with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static synchronized ChartPanel createChart(DefaultCategoryDataset dataset, String title, String categoryAxisLabel, String valueAxisLabel, PlotOrientation chartType) {

        final JFreeChart chart = ChartFactory.createBarChart(
                title,
                categoryAxisLabel,
                valueAxisLabel,
                dataset,
                chartType,
                true,
                true,
                false
        );

        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        chart.setBackgroundPaint(Color.lightGray);

        ChartPanel localChartPanel = new ChartPanel(chart);
        localChartPanel.setVisible(true);
        localChartPanel.setDomainZoomable(true);

        return localChartPanel;
    }
 
Example 2
Source File: ChartGestureDragDiffHandler.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * use default orientation or orientation of axis
 * 
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
  ChartEntity ce = event.getEntity();
  if (ce instanceof AxisEntity) {
    JFreeChart chart = event.getChart();
    PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
    if (chart.getXYPlot() != null)
      plotorient = chart.getXYPlot().getOrientation();
    else if (chart.getCategoryPlot() != null)
      plotorient = chart.getCategoryPlot().getOrientation();

    Entity entity = event.getGesture().getEntity();
    if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
        || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
      orient = Orientation.HORIZONTAL;
    else
      orient = Orientation.VERTICAL;
  }
  return orient;
}
 
Example 3
Source File: ChartGestureDragDiffHandler.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * use default orientation or orientation of axis
 * 
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
  ChartEntity ce = event.getEntity();
  if (ce instanceof AxisEntity) {
    JFreeChart chart = event.getChart();
    PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
    if (chart.getXYPlot() != null)
      plotorient = chart.getXYPlot().getOrientation();
    else if (chart.getCategoryPlot() != null)
      plotorient = chart.getCategoryPlot().getOrientation();

    Entity entity = event.getGesture().getEntity();
    if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
        || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
      orient = Orientation.HORIZONTAL;
    else
      orient = Orientation.VERTICAL;
  }
  return orient;
}
 
Example 4
Source File: ChartGestureDragDiffHandler.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * use default orientation or orientation of axis
 * 
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
  ChartEntity ce = event.getEntity();
  if (ce instanceof AxisEntity) {
    JFreeChart chart = event.getChart();
    PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
    if (chart.getXYPlot() != null)
      plotorient = chart.getXYPlot().getOrientation();
    else if (chart.getCategoryPlot() != null)
      plotorient = chart.getCategoryPlot().getOrientation();

    Entity entity = event.getGesture().getEntity();
    if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
        || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
      orient = Orientation.HORIZONTAL;
    else
      orient = Orientation.VERTICAL;
  }
  return orient;
}
 
Example 5
Source File: ChartWriterFactory.java    From entity-system-benchmarks with Apache License 2.0 6 votes vote down vote up
private static void generateChart(String benchmark, DefaultCategoryDataset dataset, int benchmarkCount) {
	JFreeChart chart = ChartFactory.createBarChart(
			benchmark, "framework", "throughput", dataset,
			PlotOrientation.HORIZONTAL, true, false, false);

	CategoryPlot plot = chart.getCategoryPlot();
	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setItemMargin(0);
	notSoUglyPlease(chart);
	
	String pngFile = getOutputName(benchmark);
	
	try {
		int height = 100 + benchmarkCount * 20;
		ChartUtilities.saveChartAsPNG(new File(pngFile), chart, 700, height);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 6
Source File: LineChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );

  final CategoryPlot cpl = chart.getCategoryPlot();
  final CategoryItemRenderer renderer = cpl.getRenderer();
  renderer.setStroke( translateLineStyle( lineWidth, lineStyle ) );
  if ( renderer instanceof LineAndShapeRenderer ) {
    final LineAndShapeRenderer shapeRenderer = (LineAndShapeRenderer) renderer;
    shapeRenderer.setShapesVisible( isMarkersVisible() );
    shapeRenderer.setBaseShapesFilled( isMarkersVisible() );
  }

}
 
Example 7
Source File: TransitionBarChart.java    From osmo with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JFreeChart createChart(String title) {
  JFreeChart chart = ChartFactory.createBarChart(title, "test", "transitions", data, PlotOrientation.VERTICAL, true, true, false);
  CategoryPlot plot = chart.getCategoryPlot();
  plot.setBackgroundPaint(Color.lightGray);
  plot.setDomainGridlinePaint(Color.white);
  plot.setRangeGridlinePaint(Color.white);
  return chart;
}
 
Example 8
Source File: ChartGestureEvent.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * True if axis is vertical, false if horizontal, null if there was an error
 * 
 * @param axis
 * @return
 */
public Boolean isVerticalAxis(ValueAxis axis) {
  if (axis == null)
    return null;
  JFreeChart chart = getChart();
  PlotOrientation orient = PlotOrientation.HORIZONTAL;
  if (chart.getXYPlot() != null)
    orient = chart.getXYPlot().getOrientation();
  else if (chart.getCategoryPlot() != null)
    orient = chart.getCategoryPlot().getOrientation();
  // error
  if (orient == null)
    return null;

  Entity entity = this.getGesture().getEntity();
  double start = 0;
  // horizontal
  if ((entity.equals(Entity.DOMAIN_AXIS) && orient.equals(PlotOrientation.VERTICAL))
      || (entity.equals(Entity.RANGE_AXIS) && orient.equals(PlotOrientation.HORIZONTAL))) {
    return false;
  }
  // vertical
  else if ((entity.equals(Entity.RANGE_AXIS) && orient.equals(PlotOrientation.VERTICAL))
      || (entity.equals(Entity.DOMAIN_AXIS) && orient.equals(PlotOrientation.HORIZONTAL))) {
    return true;
  }
  // error
  return null;
}
 
Example 9
Source File: ChartGestureEvent.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * True if axis is vertical, false if horizontal, null if there was an error
 * 
 * @param axis
 * @return
 */
public Boolean isVerticalAxis(ValueAxis axis) {
  if (axis == null)
    return null;
  JFreeChart chart = getChart();
  PlotOrientation orient = PlotOrientation.HORIZONTAL;
  if (chart.getXYPlot() != null)
    orient = chart.getXYPlot().getOrientation();
  else if (chart.getCategoryPlot() != null)
    orient = chart.getCategoryPlot().getOrientation();
  // error
  if (orient == null)
    return null;

  Entity entity = this.getGesture().getEntity();
  double start = 0;
  // horizontal
  if ((entity.equals(Entity.DOMAIN_AXIS) && orient.equals(PlotOrientation.VERTICAL))
      || (entity.equals(Entity.RANGE_AXIS) && orient.equals(PlotOrientation.HORIZONTAL))) {
    return false;
  }
  // vertical
  else if ((entity.equals(Entity.RANGE_AXIS) && orient.equals(PlotOrientation.VERTICAL))
      || (entity.equals(Entity.DOMAIN_AXIS) && orient.equals(PlotOrientation.HORIZONTAL))) {
    return true;
  }
  // error
  return null;
}
 
Example 10
Source File: AreaChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );
  final CategoryPlot cpl = chart.getCategoryPlot();

  cpl.getDomainAxis().setCategoryMargin( 0.0 );

  final CategoryItemRenderer renderer = cpl.getRenderer();
  if ( ( isStacked() ) && renderAsPercentages && ( renderer instanceof StackedAreaRenderer ) ) {
    final StackedAreaRenderer sbr = (StackedAreaRenderer) renderer;
    sbr.setRenderAsPercentages( true );
  }
}
 
Example 11
Source File: LegendShapeCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	Plot plot = jfc.getPlot();

	ItemsCounter itemsCounter = new LegendItemsCounter(plot);
	SeriesNameProvider seriesNameProvider = null;
	Object renderer = null;

	if (plot instanceof XYPlot)
	{
		XYPlot xyPlot = jfc.getXYPlot();
		renderer = xyPlot.getRenderer();
		seriesNameProvider = new XYPlotSeriesNameProvider(xyPlot);
	}
	else if (plot instanceof CategoryPlot)
	{
		CategoryPlot categoryPlot = jfc.getCategoryPlot(); 
		renderer = categoryPlot.getRenderer();
		seriesNameProvider = new CategorySeriesNameProvider(categoryPlot);
	}

	Integer legendItemIndex = CustomizerUtil.resolveIndex(this, itemsCounter, seriesNameProvider);
	if (
		legendItemIndex != null
		&& renderer instanceof AbstractRenderer
		)
	{
		ShapeSetter shapeSetter = new AbstractRendererLegendShapeSetter((AbstractRenderer)renderer);
		if (legendItemIndex == -1)
		{
			updateItems(itemsCounter, shapeSetter);
		}
		else
		{
			updateItem(itemsCounter, shapeSetter, legendItemIndex);
		}
	}
}
 
Example 12
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 13
Source File: DistributionPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createNominalChart() {
	JFreeChart chart;
	CategoryDataset dataset = createNominalDataSet();

	// create the chart...
	String domainName = dataTable == null ? MODEL_DOMAIN_AXIS_NAME : dataTable.getColumnName(plotColumn);
	chart = ChartFactory.createBarChart(null, // chart title
			domainName, // x axis label
			RANGE_AXIS_NAME, // y axis label
			dataset, // data
			PlotOrientation.VERTICAL, true, // include legend
			true, // tooltips
			false // urls
			);

	CategoryPlot plot = chart.getCategoryPlot();

	BarRenderer renderer = new BarRenderer();
	if (dataset.getRowCount() == 1) {
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);
	} else {
		for (int i = 0; i < dataset.getRowCount(); i++) {
			Color color = getColorProvider(true).getPointColor((double) i / (double) (dataset.getRowCount() - 1));
			renderer.setSeriesPaint(i, color);
			renderer.setSeriesFillPaint(i, color);
		}
	}
	renderer.setBarPainter(new RapidBarPainter());
	renderer.setDrawBarOutline(true);
	plot.setRenderer(renderer);

	// rotate labels
	if (isLabelRotating()) {
		plot.getDomainAxis().setTickLabelsVisible(true);
		plot.getDomainAxis().setCategoryLabelPositions(
				CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
	}

	return chart;
}
 
Example 14
Source File: UserChartController.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

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

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 15
Source File: LineDotShapeCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	Plot plot = jfc.getPlot();

	ItemsCounter itemsCounter = null;
	SeriesNameProvider seriesNameProvider = null;
	Object renderer = null;

	if (plot instanceof XYPlot)
	{
		XYPlot xyPlot = jfc.getXYPlot();
		renderer = xyPlot.getRenderer();
		itemsCounter = new XYPlotSeriesCounter(xyPlot);
		seriesNameProvider = new XYPlotSeriesNameProvider(xyPlot);
	}
	else if (plot instanceof CategoryPlot)
	{
		CategoryPlot categoryPlot = jfc.getCategoryPlot(); 
		renderer = categoryPlot.getRenderer();
		itemsCounter = new CategoryCounter(categoryPlot);
		seriesNameProvider = new CategorySeriesNameProvider(categoryPlot);
	}

	Integer seriesItemIndex = CustomizerUtil.resolveIndex(this, itemsCounter, seriesNameProvider);
	if (
		seriesItemIndex != null
		&& renderer instanceof AbstractRenderer
		)
	{
		ShapeSetter shapeSetter = new AbstractRendererSeriesShapeSetter((AbstractRenderer)renderer);
		if (seriesItemIndex == -1)
		{
			updateItems(itemsCounter, shapeSetter);
		}
		else
		{
			updateItem(itemsCounter, shapeSetter, seriesItemIndex);	
		}
	}
}
 
Example 16
Source File: UserChartController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

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

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 17
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;
    
}
 
Example 18
Source File: MonitoringPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
private JFreeChart createProgressChart(Map<String, Integer> chartValues, int aMaxValue,
        boolean aIsPercentage)
{
    // fill dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (aMaxValue > 0) {
        for (String chartValue : chartValues.keySet()) {
            dataset.setValue(chartValues.get(chartValue), "Completion", chartValue);
        }
    }
    
    // create chart
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset,
            PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(null);
    plot.setNoDataMessage("No data");
    plot.setInsets(new RectangleInsets(0, 20, 0, 20));
    if (aMaxValue > 0) {
        plot.getRangeAxis().setRange(0.0, aMaxValue);
        ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0"));
        // For documents less than 10, avoid repeating the number of documents such
        // as 0 0 1 1 1 - NumberTickUnit automatically determines the range
        if (!aIsPercentage && aMaxValue <= 10) {
            TickUnits standardUnits = new TickUnits();
            NumberAxis tick = new NumberAxis();
            tick.setTickUnit(new NumberTickUnit(1));
            standardUnits.add(tick.getTickUnit());
            plot.getRangeAxis().setStandardTickUnits(standardUnits);
        }
    }
    else {
        plot.getRangeAxis().setVisible(false);
        plot.getDomainAxis().setVisible(false);
    }

    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    // renderer.setGradientPaintTransformer(new
    // StandardGradientPaintTransformer(
    // GradientPaintTransformType.HORIZONTAL));
    renderer.setSeriesPaint(0, Color.BLUE);
    chart.getCategoryPlot().setRenderer(renderer);

    return chart;
}
 
Example 19
Source File: UserChartController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

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

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 20
Source File: MotivationalViewer.java    From cst with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void run() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createBarChart(
            getTitle(),
            getEntity(),
            "Value",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    chart.setBackgroundPaint(Color.lightGray);

    ChartFrame frame= new ChartFrame(getTitle(), chart);
    frame.pack();
    frame.setVisible(true);

    while (true) {
        ArrayList<Codelet> tempCodeletsList = new ArrayList<Codelet>();
        tempCodeletsList.addAll(this.getListOfMotivationalEntities());

        synchronized (tempCodeletsList) {

            for (Codelet co : tempCodeletsList) {
                dataset.addValue(co.getActivation(), co.getName(), "activation");
            }
            try {
                Thread.currentThread().sleep(getRefreshPeriod());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}