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

The following examples show how to use org.jfree.chart.JFreeChart#setBorderVisible() . 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: ThermometerChartExpression.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 Plot plot = chart.getPlot();
  final ThermometerPlot thermometerPlot = (ThermometerPlot) plot;

  if ( isShowBorder() == false || isChartSectionOutline() == false ) {
    chart.setBorderVisible( false );
    thermometerPlot.setOutlineVisible( false );
  }

  if ( getThermometerUnits() != null ) {
    thermometerPlot.setUnits( getThermometerUnits().getUnitConstant() );
  }
  thermometerPlot
    .setLowerBound( Math.min( getCriticalRangeLow(), Math.min( getNormalRangeLow(), getWarningRangeLow() ) ) );
  thermometerPlot
    .setUpperBound( Math.max( getCriticalRangeHigh(), Math.max( getNormalRangeHigh(), getWarningRangeHigh() ) ) );
  thermometerPlot.setBulbRadius( getBulbRadius() );
  thermometerPlot.setColumnRadius( getColumnRadius() );
  thermometerPlot.setSubrange( ThermometerPlot.CRITICAL, getCriticalRangeLow(), getCriticalRangeHigh() );
  thermometerPlot.setSubrange( ThermometerPlot.WARNING, getWarningRangeLow(), getWarningRangeHigh() );
  thermometerPlot.setSubrange( ThermometerPlot.NORMAL, getNormalRangeLow(), getNormalRangeHigh() );
  if ( getMercuryPaint() != null ) {
    thermometerPlot.setMercuryPaint( getMercuryPaint() );
  }
  if ( getThermometerPaint() != null ) {
    thermometerPlot.setThermometerPaint( getThermometerPaint() );
  }

  if ( getCriticalRangeColor() != null ) {
    thermometerPlot.setSubrangePaint( ThermometerPlot.CRITICAL, getCriticalRangeColor() );
  }
  if ( getWarningRangeColor() != null ) {
    thermometerPlot.setSubrangePaint( ThermometerPlot.WARNING, getWarningRangeColor() );
  }
  if ( getNormalRangeColor() != null ) {
    thermometerPlot.setSubrangePaint( ThermometerPlot.NORMAL, getNormalRangeColor() );
  }
}
 
Example 2
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 3
Source File: PieChartWrapper.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createChart() {
    // create the chart...
    pieDataSet = createDataset();
    final JFreeChart chart = ChartFactory.createPieChart3D("", // chart
            // title
            pieDataSet, // data
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.getTitle().setPaint(new Color(0x5E5E5E));
    chart.setBorderVisible(false);
    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setStartAngle(290);
    plot.setBackgroundPaint(Color.white);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");
    plot.setLabelGenerator(new JFreeChartLabelCustom());

    final List keys = pieDataSet.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final Comparable key = (Comparable) keys.get(i);
        int colorIndex = i % CHART_COLOR_STR.size();
        plot.setSectionPaint(key, Color.decode("0x" + CHART_COLOR_STR.get(colorIndex)));
    }
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}
 
Example 4
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] createToolAnalysisChart (int width, int height)
{
	CategoryDataset dataset = getToolAnalysisDataSet ();
	
	if (dataset == null) {
		return generateNoDataChart(width, height);
	}
			
	JFreeChart chart = ChartFactory.createBarChart (
			null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.HORIZONTAL, // the plot orientation
			false, // legend
			false, // 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 (false);
	plot.setRangeGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);
	
       CategoryAxis domainAxis = plot.getDomainAxis();
       domainAxis.setVisible(false);
       domainAxis.setUpperMargin (0);
       domainAxis.setLowerMargin (0);
       
       NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
       rangeAxis.setUpperMargin(0.20);
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
       
       BarRenderer renderer = (BarRenderer) plot.getRenderer();
       CategoryItemLabelGenerator generator 
           = new StandardCategoryItemLabelGenerator("{1}", 
                   NumberFormat.getInstance(new ResourceLoader().getLocale()));
       renderer.setDefaultItemLabelGenerator(generator);
       renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
       renderer.setDefaultItemLabelsVisible(true);
       renderer.setItemMargin (0);
       renderer.setSeriesPaint (0, Color.BLUE);
       
       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 5
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 6
Source File: PieChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );

  final Plot plot = chart.getPlot();
  final PiePlot pp = (PiePlot) plot;
  final PieDataset pieDS = pp.getDataset();
  pp.setDirection( rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE );
  if ( ( explodeSegment != null ) && ( explodePct != null ) ) {
    configureExplode( pp );
  }
  if ( StringUtils.isEmpty( getTooltipFormula() ) == false ) {
    pp.setToolTipGenerator( new FormulaPieTooltipGenerator( getRuntime(), getTooltipFormula() ) );
  }
  if ( StringUtils.isEmpty( getUrlFormula() ) == false ) {
    pp.setURLGenerator( new FormulaPieURLGenerator( getRuntime(), getUrlFormula() ) );
  }

  pp.setIgnoreNullValues( ignoreNulls );
  pp.setIgnoreZeroValues( ignoreZeros );
  if ( Boolean.FALSE.equals( getItemsLabelVisible() ) ) {
    pp.setLabelGenerator( null );
  } else {
    final ExpressionRuntime runtime = getRuntime();
    final Locale locale = runtime.getResourceBundleFactory().getLocale();

    final FastDecimalFormat fastPercent = new FastDecimalFormat( FastDecimalFormat.TYPE_PERCENT, locale, true );
    final FastDecimalFormat fastInteger = new FastDecimalFormat( FastDecimalFormat.TYPE_INTEGER, locale, true );

    final DecimalFormat numFormat = new DecimalFormat( fastInteger.getPattern(), new DecimalFormatSymbols( locale ) );
    numFormat.setRoundingMode( RoundingMode.HALF_UP );

    final DecimalFormat percentFormat =
      new DecimalFormat( fastPercent.getPattern(), new DecimalFormatSymbols( locale ) );
    percentFormat.setRoundingMode( RoundingMode.HALF_UP );

    final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( pieLabelFormat,
      numFormat, percentFormat );
    pp.setLabelGenerator( labelGen );

    final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat,
      numFormat, percentFormat );
    pp.setLegendLabelGenerator( legendGen );
  }

  if ( StringUtils.isEmpty( getLabelFont() ) == false ) {
    pp.setLabelFont( Font.decode( getLabelFont() ) );
  }

  if ( pieDS != null ) {
    final String[] colors = getSeriesColor();
    for ( int i = 0; i < colors.length; i++ ) {
      if ( i < pieDS.getItemCount() ) {
        pp.setSectionPaint( pieDS.getKey( i ), parseColorFromString( colors[ i ] ) );
      } else {
        break;
      }
    }
  }

  if ( shadowPaint != null ) {
    pp.setShadowPaint( shadowPaint );
  }
  if ( shadowXOffset != null ) {
    pp.setShadowXOffset( shadowXOffset.doubleValue() );
  }
  if ( shadowYOffset != null ) {
    pp.setShadowYOffset( shadowYOffset.doubleValue() );
  }
  pp.setCircular( circular );

  if ( isShowBorder() == false || isChartSectionOutline() == false ) {
    chart.setBorderVisible( false );
    chart.getPlot().setOutlineVisible( false );
  }

}
 
Example 7
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 8
Source File: SWTMultipleAxisDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 * 
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 
            200);
    
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3", 
        "Time of Day", 
        "Primary Range Axis",
        dataset1, 
        true, 
        true, 
        false
    );

    chart.setBackgroundPaint( Color.white );
    chart.setBorderVisible( true );
    chart.setBorderPaint( Color.BLACK );
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");  
    chart.addSubtitle( subtitle );
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
   
    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);
    
    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible( true );
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4        
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);
    
    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);
    
    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);        
    plot.setRenderer(3, renderer4);
            
    return chart;
}
 
Example 9
Source File: SWTMultipleAxisDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 10
Source File: SWTMultipleAxisDemo1.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 11
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] createToolAnalysisChart (int width, int height)
{
	CategoryDataset dataset = getToolAnalysisDataSet ();
	
	if (dataset == null) {
		return generateNoDataChart(width, height);
	}
			
	JFreeChart chart = ChartFactory.createBarChart (
			null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.HORIZONTAL, // the plot orientation
			false, // legend
			false, // 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 (false);
	plot.setRangeGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);
	
       CategoryAxis domainAxis = plot.getDomainAxis();
       domainAxis.setVisible(false);
       domainAxis.setUpperMargin (0);
       domainAxis.setLowerMargin (0);
       
       NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
       rangeAxis.setUpperMargin(0.20);
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
       
       BarRenderer renderer = (BarRenderer) plot.getRenderer();
       CategoryItemLabelGenerator generator 
           = new StandardCategoryItemLabelGenerator("{1}", 
                   NumberFormat.getInstance(new ResourceLoader().getLocale()));
       renderer.setDefaultItemLabelGenerator(generator);
       renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
       renderer.setDefaultItemLabelsVisible(true);
       renderer.setItemMargin (0);
       renderer.setSeriesPaint (0, Color.BLUE);
       
       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 12
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 13
Source File: SWTMultipleAxisDemo1.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 14
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 15
Source File: ChartServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] generatePieChart(
		String siteId, PieDataset dataset, int width, int height,
		boolean render3d, float transparency,
		boolean smallFontInDomainAxis) {
	JFreeChart chart = null;
	if(render3d)
		chart = ChartFactory.createPieChart3D(null, dataset, false, false, false);
	else
		chart = ChartFactory.createPieChart(null, dataset, false, false, false);
	PiePlot plot = (PiePlot) chart.getPlot();
	
	// set start angle (135 or 150 deg so minor data has more space on the left)
	plot.setStartAngle(150D);
	
	// set transparency
	plot.setForegroundAlpha(transparency);
	
	// set background
	chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));
	plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));
	
	// fix border offset		
	chart.setPadding(new RectangleInsets(5,5,5,5));
	plot.setInsets(new RectangleInsets(1,1,1,1));
	// set chart border
	plot.setOutlinePaint(null);
	chart.setBorderVisible(true);
	chart.setBorderPaint(parseColor("#cccccc"));
	
	// set antialias
	chart.setAntiAlias(true);
	
	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 16
Source File: MinimapPanel.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
private void renderChartInfo() {
    HashMap<Object, Marker> marks = new HashMap<>();
    DefaultPieDataset dataset = buildDataset(marks);

    JFreeChart chart = ChartFactory.createPieChart(
            null, // chart title
            dataset, // data
            true, // include legend
            true,
            false);
    chart.setBackgroundPaint(null);
    //chart.setBorderStroke(null);
    chart.setBorderVisible(false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    // plot.setBackgroundPaint(null);
    //  plot.setShadowPaint(null);

    for(Object o: marks.keySet()) {
        if (iCurrentView == ID_ALLY_CHART) {
            Ally a = (Ally) o;
            plot.setSectionPaint(a.getTag(), marks.get(a).getMarkerColor());
        } else {
            Tribe t = (Tribe) o;
            plot.setSectionPaint(t.getName(), marks.get(t).getMarkerColor());
        }
    }
    //plot.setCircular(true);
    //  plot.setMaximumLabelWidth(30.0);
 /*
     * plot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} = {2}", NumberFormat.getNumberInstance(),
     * NumberFormat.getPercentInstance()));
     */
    //   chart.getLegend().setVerticalAlignment(VerticalAlignment.CENTER);
    //  chart.getLegend().setPosition(RectangleEdge.RIGHT);
    // plot.setMaximumLabelWidth(20.0);
    plot.setLabelGenerator(null);
    plot.setBackgroundPaint(Constants.DS_BACK);
    /*
     * plot.setInteriorGap(0.0); plot.setLabelGap(0.0);
     */
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
            "{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));

    /*
     * plot.getL plot.setLabelFont(g2d.getFont().deriveFont(10.0f));
     */


    //plot.setLabelGenerator(null);

    //plot.setMaximumLabelWidth(30.0);
    //plot.getLabelDistributor().distributeLabels(10.0, 20.0);
    //chart.draw(g2d, new Rectangle2D.Float(20, 20, 100, 100));

    //  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    plot.setOutlineVisible(false);
    mChartImage = chart.createBufferedImage(getWidth(), getHeight());
    //chart.draw(g2d, new Rectangle2D.Float(50, 50, 400, 400));
    //g2d.drawImage(bi, 30, 30, null);

    //  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));

    //bi = chart.createBufferedImage(240, 240);
    // g2d.drawImage(bi, 30, 30, null);
}
 
Example 17
Source File: AbstractChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  // Misc Properties
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    final Font titleFont = Font.decode( getTitleFont() );
    chartTitle.setFont( titleFont );
  }

  if ( isAntiAlias() == false ) {
    chart.setAntiAlias( false );
  }

  chart.setBorderVisible( isShowBorder() );

  final Color backgroundColor = parseColorFromString( getBackgroundColor() );
  if ( backgroundColor != null ) {
    chart.setBackgroundPaint( backgroundColor );
  }

  if ( plotBackgroundColor != null ) {
    chart.getPlot().setBackgroundPaint( plotBackgroundColor );
  }
  chart.getPlot().setBackgroundAlpha( plotBackgroundAlpha );
  chart.getPlot().setForegroundAlpha( plotForegroundAlpha );
  final Color borderCol = parseColorFromString( getBorderColor() );
  if ( borderCol != null ) {
    chart.setBorderPaint( borderCol );
  }

  //remove legend if showLegend = false
  if ( !isShowLegend() ) {
    chart.removeLegend();
  } else { //if true format legend
    final LegendTitle chLegend = chart.getLegend();
    if ( chLegend != null ) {
      final RectangleEdge loc = translateEdge( legendLocation.toLowerCase() );
      if ( loc != null ) {
        chLegend.setPosition( loc );
      }
      if ( getLegendFont() != null ) {
        chLegend.setItemFont( Font.decode( getLegendFont() ) );
      }
      if ( !isDrawLegendBorder() ) {
        chLegend.setBorder( BlockBorder.NONE );
      }
      if ( legendBackgroundColor != null ) {
        chLegend.setBackgroundPaint( legendBackgroundColor );
      }
      if ( legendTextColor != null ) {
        chLegend.setItemPaint( legendTextColor );
      }
    }

  }

  final Plot plot = chart.getPlot();
  plot.setNoDataMessageFont( Font.decode( getLabelFont() ) );

  final String message = getNoDataMessage();
  if ( message != null ) {
    plot.setNoDataMessage( message );
  }

  plot.setOutlineVisible( isChartSectionOutline() );

  if ( backgroundImage != null ) {
    if ( plotImageCache != null ) {
      plot.setBackgroundImage( plotImageCache );
    } else {
      final ExpressionRuntime expressionRuntime = getRuntime();
      final ProcessingContext context = expressionRuntime.getProcessingContext();
      final ResourceKey contentBase = context.getContentBase();
      final ResourceManager manager = context.getResourceManager();
      try {
        final ResourceKey key = createKeyFromString( manager, contentBase, backgroundImage );
        final Resource resource = manager.create( key, null, Image.class );
        final Image image = (Image) resource.getResource();
        plot.setBackgroundImage( image );
        plotImageCache = image;
      } catch ( Exception e ) {
        logger.error( "ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e ); //$NON-NLS-1$
        throw new IllegalStateException( "Failed to process chart" );
      }
    }
  }
}
 
Example 18
Source File: LinearExecutionChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = ( CategoryPlot ) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index ++ , GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index ++ , Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable< ? > valueKey = data.getColumnKey(category);
            ChartLongValue value = ( ChartLongValue ) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ( ( NumberAxis ) rangeAxis ).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}
 
Example 19
Source File: SWTMultipleAxisDemo1.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 20
Source File: SWTMultipleAxisDemo1.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}