org.jfree.chart.ui.RectangleInsets Java Examples

The following examples show how to use org.jfree.chart.ui.RectangleInsets. 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: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
public static StandardChartTheme initializeTheme() {
    String fontName = "Arial";
    StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    return theme;
}
 
Example #2
Source File: KovatsIndexExtractionDialog.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * replace markers
 */
private void kovatsValuesChanged() {
  // parse values
  if (parseValues() && chart != null) {
    //
    chart.getChart().getXYPlot().clearDomainMarkers();
    if (markers == null)
      markers = new ArrayList<>();
    else
      markers.clear();

    for (Entry<KovatsIndex, Double> e : parsedValues.entrySet()) {
      ValueMarker marker = new ValueMarker(e.getValue(),
          MZmineCore.getConfiguration().getDefaultColorPalette()
              .getPositiveColorAWT(), markerStroke);

      marker.setLabelOffset(new RectangleInsets(10, 0, 0, 0));
      marker.setLabelFont(new Font("Arial", Font.PLAIN, 12));
      marker.setLabelBackgroundColor(Color.WHITE);
      marker.setLabel(e.getKey().getShortName());
      chart.getChart().getXYPlot().addDomainMarker(marker);
      markers.add(marker);
    }

    // revalidate();
    // repaint();
  }
}
 
Example #3
Source File: ChartThemeFactory2.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a chart theme with no axis offset better suited for exporting due to a cleaner look.
 *
 * @param name
 * @return
 */
public static EStandardChartTheme createExportChartTheme(String name) {
  EStandardChartTheme theme = createDefaultTheme(name);
  theme.setDefaultAxisOffset(RectangleInsets.ZERO_INSETS);
  theme.setMirrorPlotAxisOffset(RectangleInsets.ZERO_INSETS);
  return theme;
}
 
Example #4
Source File: ChartTheme.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
private static StandardChartTheme getChartTheme(StandardChartTheme standardChartTheme, boolean shadow) {
    standardChartTheme.setExtraLargeFont(new Font(Font.DIALOG, Font.BOLD, 24));
    standardChartTheme.setLargeFont(new Font(Font.DIALOG, Font.PLAIN, 18));
    standardChartTheme.setRegularFont(new Font(Font.DIALOG, Font.PLAIN, 14));
    standardChartTheme.setSmallFont(new Font(Font.DIALOG, Font.PLAIN, 10));
    standardChartTheme.setTitlePaint(Color.BLACK);
    standardChartTheme.setSubtitlePaint(Color.BLACK);
    standardChartTheme.setLegendBackgroundPaint(Color.WHITE);
    standardChartTheme.setLegendItemPaint(Color.BLACK);
    standardChartTheme.setChartBackgroundPaint(Color.WHITE);
    standardChartTheme.setDrawingSupplier(new DefaultDrawingSupplier());
    standardChartTheme.setPlotBackgroundPaint(Color.WHITE);
    standardChartTheme.setPlotOutlinePaint(Color.BLACK);
    standardChartTheme.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
    standardChartTheme.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
    standardChartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY);
    standardChartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY);
    standardChartTheme.setBaselinePaint(Color.BLACK);
    standardChartTheme.setCrosshairPaint(Color.BLACK);
    standardChartTheme.setAxisLabelPaint(Color.DARK_GRAY);
    standardChartTheme.setTickLabelPaint(Color.DARK_GRAY);
    standardChartTheme.setBarPainter(new StandardBarPainter());
    standardChartTheme.setXYBarPainter(new StandardXYBarPainter());
    standardChartTheme.setShadowVisible(shadow);
    standardChartTheme.setItemLabelPaint(Color.BLACK);
    standardChartTheme.setThermometerPaint(Color.WHITE);
    standardChartTheme.setErrorIndicatorPaint(Color.RED);
    return standardChartTheme;
}
 
Example #5
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a horizontal line marker for the given x value and label.
 */
private Marker getMarker( Double value, String label )
{
    Marker marker = new ValueMarker( value );
    marker.setPaint( Color.BLACK );
    marker.setStroke( new BasicStroke( 1.1f ) );
    marker.setLabel( label );
    marker.setLabelOffset( new RectangleInsets( -10, 50, 0, 0 ) );
    marker.setLabelFont( SUB_TITLE_FONT );

    return marker;
}
 
Example #6
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a horizontal line marker for the given x value and label.
 */
private Marker getMarker(Double value, String label )
{
    Marker marker = new ValueMarker( value );
    marker.setPaint( Color.BLACK );
    marker.setStroke( new BasicStroke( 1.1f ) );
    marker.setLabel( label );
    marker.setLabelOffset( new RectangleInsets( -10, 50, 0, 0 ) );
    marker.setLabelFont( SUB_TITLE_FONT );

    return marker;
}
 
Example #7
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 #8
Source File: KovatsIndexExtractionDialog.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * replace markers
 */
private void kovatsValuesChanged() {
  // parse values
  if (parseValues() && chart != null) {
    //
    chart.getChart().getXYPlot().clearDomainMarkers();
    if (markers == null)
      markers = new ArrayList<>();
    else
      markers.clear();

    for (Entry<KovatsIndex, Double> e : parsedValues.entrySet()) {
      ValueMarker marker = new ValueMarker(e.getValue(),
          ColorPalettes.getPositiveColor(MZmineCore.getConfiguration().getColorVision()),
          markerStroke);
      marker.setLabelOffset(new RectangleInsets(10, 0, 0, 0));
      marker.setLabelFont(new Font("Arial", Font.PLAIN, 12));
      marker.setLabelBackgroundColor(Color.WHITE);
      marker.setLabel(e.getKey().getShortName());
      chart.getChart().getXYPlot().addDomainMarker(marker);
      markers.add(marker);
    }

    revalidate();
    repaint();
  }
}
 
Example #9
Source File: DSWorkbenchStatsFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void setupPlotDrawing(XYPlot pPlot) {
    pPlot.setBackgroundPaint(Constants.DS_BACK_LIGHT);
    pPlot.setDomainGridlinePaint(Color.DARK_GRAY);
    pPlot.setRangeGridlinePaint(Color.DARK_GRAY);
    pPlot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    pPlot.setDomainCrosshairVisible(true);
    pPlot.setRangeCrosshairVisible(true);
    
    DateAxis axis = (DateAxis) pPlot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"));
}
 
Example #10
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 #11
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 #12
Source File: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 4 votes vote down vote up
public void initializePlot( XYPlot xyplot ) {
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    rangeAxis.setRange(-9.99, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    
    domainAxis.setRange(-5, 175);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);
    xyplot.setOutlineVisible(true);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    
    Point2D legendLocation = new Point2D.Double( 101, -10 );
    makeRect(xyplot, legendLocation, 120, 74, Color.WHITE );
   
    Point2D triangleLocation = new Point2D.Double( 101, -10 );
    Color grey = new Color(0.1f,0.1f,0.1f,0.1f);
    makeTriangle(xyplot, triangleLocation, grey );
    
    makeGuessingLine( xyplot );
}
 
Example #13
Source File: ChartThemeFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static EStandardChartTheme createBlackNWhiteTheme() {
  EStandardChartTheme theme = new EStandardChartTheme(THEME.BNW_PRINT, "BnW");
  // Fonts
  theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 16));
  theme.setLargeFont(new Font("Arial", Font.BOLD, 11));
  theme.setRegularFont(new Font("Arial", Font.PLAIN, 11));
  theme.setSmallFont(new Font("Arial", Font.PLAIN, 11));

  // Paints
  theme.setTitlePaint(Color.black);
  theme.setSubtitlePaint(Color.black);
  theme.setLegendItemPaint(Color.black);
  theme.setPlotOutlinePaint(Color.black);
  theme.setBaselinePaint(Color.black);
  theme.setCrosshairPaint(Color.black);
  theme.setLabelLinkPaint(Color.black);
  theme.setTickLabelPaint(Color.black);
  theme.setAxisLabelPaint(Color.black);
  theme.setShadowPaint(Color.black);
  theme.setItemLabelPaint(Color.black);

  theme.setLegendBackgroundPaint(Color.white);
  theme.setChartBackgroundPaint(Color.white);
  theme.setPlotBackgroundPaint(Color.white);

  // paint sequence: add black
  Paint[] colors = new Paint[] {Color.BLACK, new Color(0xFF, 0x55, 0x55),
      new Color(0x55, 0x55, 0xFF), new Color(0x55, 0xFF, 0x55), new Color(0xFF, 0xFF, 0x55),
      new Color(0xFF, 0x55, 0xFF), new Color(0x55, 0xFF, 0xFF), Color.pink, Color.gray,
      ChartColor.DARK_RED, ChartColor.DARK_BLUE, ChartColor.DARK_GREEN, ChartColor.DARK_YELLOW,
      ChartColor.DARK_MAGENTA, ChartColor.DARK_CYAN, Color.darkGray, ChartColor.LIGHT_RED,
      ChartColor.LIGHT_BLUE, ChartColor.LIGHT_GREEN, ChartColor.LIGHT_YELLOW,
      ChartColor.LIGHT_MAGENTA, ChartColor.LIGHT_CYAN, Color.lightGray, ChartColor.VERY_DARK_RED,
      ChartColor.VERY_DARK_BLUE, ChartColor.VERY_DARK_GREEN, ChartColor.VERY_DARK_YELLOW,
      ChartColor.VERY_DARK_MAGENTA, ChartColor.VERY_DARK_CYAN, ChartColor.VERY_LIGHT_RED,
      ChartColor.VERY_LIGHT_BLUE, ChartColor.VERY_LIGHT_GREEN, ChartColor.VERY_LIGHT_YELLOW,
      ChartColor.VERY_LIGHT_MAGENTA, ChartColor.VERY_LIGHT_CYAN};

  theme.setDrawingSupplier(
      new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
          DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
          DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
          DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
          DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
  theme.setErrorIndicatorPaint(Color.black);
  theme.setGridBandPaint(new Color(255, 255, 255, 20));
  theme.setGridBandAlternatePaint(new Color(255, 255, 255, 40));

  // axis
  Color transp = new Color(0, 0, 0, 200);
  theme.setRangeGridlinePaint(transp);
  theme.setDomainGridlinePaint(transp);

  theme.setAxisLinePaint(Color.black);

  // axis offset
  theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

  return theme;
}
 
Example #14
Source File: ChartThemeFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates and returns a theme called "Darkness". In this theme, the charts have a black
 * background and white lines and labels
 *
 * @return The "Darkness" theme.
 */
public static EStandardChartTheme createDarknessTheme() {
  EStandardChartTheme theme = new EStandardChartTheme(THEME.DARKNESS, "Darkness");
  // Fonts
  theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 20));
  theme.setLargeFont(new Font("Arial", Font.BOLD, 11));
  theme.setRegularFont(new Font("Arial", Font.PLAIN, 11));
  theme.setSmallFont(new Font("Arial", Font.PLAIN, 11));
  //
  theme.setTitlePaint(Color.white);
  theme.setSubtitlePaint(Color.white);
  theme.setLegendBackgroundPaint(Color.black);
  theme.setLegendItemPaint(Color.white);
  theme.setChartBackgroundPaint(Color.black);
  theme.setPlotBackgroundPaint(Color.black);
  theme.setPlotOutlinePaint(Color.yellow);
  theme.setBaselinePaint(Color.white);
  theme.setCrosshairPaint(Color.red);
  theme.setLabelLinkPaint(Color.lightGray);
  theme.setTickLabelPaint(Color.white);
  theme.setAxisLabelPaint(Color.white);
  theme.setShadowPaint(Color.darkGray);
  theme.setItemLabelPaint(Color.white);
  theme.setDrawingSupplier(new DefaultDrawingSupplier(
      new Paint[] {Color.WHITE, Color.decode("0xFFFF00"), Color.decode("0x0036CC"),
          Color.decode("0xFF0000"), Color.decode("0xFFFF7F"), Color.decode("0x6681CC"),
          Color.decode("0xFF7F7F"), Color.decode("0xFFFFBF"), Color.decode("0x99A6CC"),
          Color.decode("0xFFBFBF"), Color.decode("0xA9A938"), Color.decode("0x2D4587")},
      new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC")},
      new Stroke[] {new BasicStroke(2.0f)}, new Stroke[] {new BasicStroke(0.5f)},
      DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
  theme.setErrorIndicatorPaint(Color.lightGray);
  theme.setGridBandPaint(new Color(255, 255, 255, 20));
  theme.setGridBandAlternatePaint(new Color(255, 255, 255, 40));

  // axis
  Color transp = new Color(255, 255, 255, 200);
  theme.setRangeGridlinePaint(transp);
  theme.setDomainGridlinePaint(transp);

  theme.setAxisLinePaint(Color.white);

  theme.setMasterFontColor(Color.WHITE);
  // axis offset
  theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
  return theme;
}
 
Example #15
Source File: ScatterPlotChart.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public ScatterPlotChart(ScatterPlotWindow window, ScatterPlotTopPanel topPanel,
    PeakList peakList) {

  super(null, true);

  this.window = window;
  this.peakList = peakList;
  this.topPanel = topPanel;

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createXYLineChart("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      false, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // Set the domain log axis
  LogAxis logAxisDomain = new LogAxis();
  logAxisDomain.setMinorTickCount(1);
  logAxisDomain.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
  logAxisDomain.setAutoRange(true);
  plot.setDomainAxis(logAxisDomain);

  // Set the range log axis
  LogAxis logAxisRange = new LogAxis();
  logAxisRange.setMinorTickCount(1);
  logAxisRange.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
  logAxisRange.setAutoRange(true);
  plot.setRangeAxis(logAxisRange);

  // Set crosshair properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // Create data sets;
  mainDataSet = new ScatterPlotDataSet(peakList);
  plot.setDataset(0, mainDataSet);
  diagonalLineDataset = new DiagonalLineDataset();
  plot.setDataset(1, diagonalLineDataset);

  // Create renderers
  mainRenderer = new ScatterPlotRenderer();
  plot.setRenderer(0, mainRenderer);
  diagonalLineRenderer = new DiagonalLineRenderer();
  plot.setRenderer(1, diagonalLineRenderer);

  // Set tooltip properties
  ttm = new ComponentToolTipManager();
  ttm.registerComponent(this);
  setDismissDelay(Integer.MAX_VALUE);
  setInitialDelay(0);

  // add items to popup menu TODO: add other Show... items
  JPopupMenu popupMenu = getPopupMenu();
  popupMenu.addSeparator();
  GUIUtils.addMenuItem(popupMenu, "Show Chromatogram", this, "TIC");

  // Add EMF and EPS options to the save as menu
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example #16
Source File: HistogramChart.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public HistogramChart() {
  super(null, true);

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createHistogram("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  // title
  chartTitle = chart.getTitle();
  chartTitle.setFont(titleFont);
  chartTitle.setMargin(5, 0, 0, 0);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // legend constructed by ChartFactory
  LegendTitle legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(true);

  // set the logarithmic axis
  NumberAxis axisDomain = new HistogramDomainAxis();
  axisDomain.setMinorTickCount(1);
  axisDomain.setAutoRange(true);

  NumberAxis axisRange = new NumberAxis();
  axisRange.setMinorTickCount(1);
  axisRange.setAutoRange(true);

  plot.setDomainAxis(axisDomain);
  plot.setRangeAxis(axisRange);

  ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
  renderer.setMargin(marginSize);
  renderer.setShadowVisible(false);
  plot.setRenderer(renderer);

  this.setMinimumSize(new Dimension(400, 400));
  this.setDismissDelay(Integer.MAX_VALUE);
  this.setInitialDelay(0);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example #17
Source File: ChartThemeFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the theme called "Karst". In this theme, the charts have a blue background and yellow
 * lines and labels.
 *
 * @return The "Karst" theme.
 */
public static EStandardChartTheme createKarstTheme() {
  EStandardChartTheme theme = new EStandardChartTheme(THEME.KARST, "Karst");
  // Fonts
  theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 20));
  theme.setLargeFont(new Font("Arial", Font.BOLD, 11));
  theme.setRegularFont(new Font("Arial", Font.PLAIN, 11));
  theme.setSmallFont(new Font("Arial", Font.PLAIN, 11));
  //
  Paint bg = new Color(50, 50, 202);
  //
  theme.setTitlePaint(Color.green);
  theme.setSubtitlePaint(Color.yellow);
  theme.setLegendBackgroundPaint(bg);
  theme.setLegendItemPaint(Color.yellow);
  theme.setChartBackgroundPaint(bg);
  theme.setPlotBackgroundPaint(bg);
  theme.setPlotOutlinePaint(Color.yellow);
  theme.setBaselinePaint(Color.white);
  theme.setCrosshairPaint(Color.red);
  theme.setLabelLinkPaint(Color.lightGray);
  theme.setTickLabelPaint(Color.yellow);
  theme.setAxisLabelPaint(Color.yellow);
  theme.setShadowPaint(Color.darkGray);
  theme.setItemLabelPaint(Color.yellow);
  theme.setDrawingSupplier(new DefaultDrawingSupplier(
      new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC"), Color.decode("0xFF0000"),
          Color.decode("0xFFFF7F"), Color.decode("0x6681CC"), Color.decode("0xFF7F7F"),
          Color.decode("0xFFFFBF"), Color.decode("0x99A6CC"), Color.decode("0xFFBFBF"),
          Color.decode("0xA9A938"), Color.decode("0x2D4587")},
      new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC")},
      new Stroke[] {new BasicStroke(2.0f)}, new Stroke[] {new BasicStroke(0.5f)},
      DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
  theme.setErrorIndicatorPaint(Color.lightGray);
  theme.setGridBandPaint(new Color(255, 255, 255, 20));
  theme.setGridBandAlternatePaint(new Color(255, 255, 255, 40));

  // axis
  Color transp = new Color(255, 255, 255, 200);
  theme.setRangeGridlinePaint(transp);
  theme.setDomainGridlinePaint(transp);

  theme.setAxisLinePaint(Color.yellow);
  theme.setMasterFontColor(Color.yellow);

  // axis offset
  theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
  return theme;
}
 
Example #18
Source File: PseudoSpectrum.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, RawDataFile raw, boolean sum,
    String title) {
  //
  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzFormat);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  return chart;
}
 
Example #19
Source File: SpectrumChartFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, boolean showTitle,
    boolean showLegend, double rt, double precursorMZ) {
  //
  if (dataset == null)
    return null;
  //
  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  String title = "";
  if (precursorMZ == 0)
    title = "RT=" + mzForm.format(precursorMZ);
  else
    title = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(precursorMZ),
        rtForm.format(rt));

  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);
  //
  if (precursorMZ != 0)
    addPrecursorMarker(chart, precursorMZ);
  return chart;
}
 
Example #20
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 #21
Source File: ProjectionPlotPanel.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public ProjectionPlotPanel(ProjectionPlotWindow masterFrame, ProjectionPlotDataset dataset,
    ParameterSet parameters) {
  super(null);

  boolean createLegend = false;
  if ((dataset.getNumberOfGroups() > 1) && (dataset.getNumberOfGroups() < 20))
    createLegend = true;

  chart = ChartFactory.createXYAreaChart("", dataset.getXLabel(), dataset.getYLabel(), dataset,
      PlotOrientation.VERTICAL, createLegend, false, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  plot.setForegroundAlpha(dataPointAlpha);

  NumberFormat numberFormat = NumberFormat.getNumberInstance();

  // set the X axis (component 1) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(numberFormat);

  // set the Y axis (component 2) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(numberFormat);

  plot.setDataset(dataset);

  spotRenderer = new ProjectionPlotRenderer(plot, dataset);
  itemLabelGenerator = new ProjectionPlotItemLabelGenerator(parameters);
  spotRenderer.setDefaultItemLabelGenerator(itemLabelGenerator);
  spotRenderer.setDefaultItemLabelsVisible(true);
  spotRenderer.setDefaultToolTipGenerator(new ProjectionPlotToolTipGenerator(parameters));
  plot.setRenderer(spotRenderer);

  // Setup legend
  if (createLegend) {
    LegendItemCollection legendItemsCollection = new LegendItemCollection();
    for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {
      Object paramValue = dataset.getGroupParameterValue(groupNumber);
      if (paramValue == null) {
        // No parameter value available: search for raw data files
        // within this group, and use their names as group's name
        String fileNames = new String();
        for (int itemNumber = 0; itemNumber < dataset.getItemCount(0); itemNumber++) {
          String rawDataFile = dataset.getRawDataFile(itemNumber);
          if (dataset.getGroupNumber(itemNumber) == groupNumber)
            fileNames = fileNames.concat(rawDataFile);
        }
        if (fileNames.length() == 0)
          fileNames = "Empty group";

        paramValue = fileNames;
      }
      Color nextColor = (Color) spotRenderer.getGroupPaint(groupNumber);
      Color groupColor = new Color(nextColor.getRed(), nextColor.getGreen(), nextColor.getBlue(),
          (int) Math.round(255 * dataPointAlpha));
      legendItemsCollection.add(new LegendItem(paramValue.toString(), "-", null, null,
          spotRenderer.getDataPointsShape(), groupColor));
    }
    plot.setFixedLegendItems(legendItemsCollection);
  }

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example #22
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 #23
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 #24
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 #25
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 #26
Source File: ChartJFreeChartOutputScatter.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	final XYPlot pp = (XYPlot) chart.getPlot();
	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setDomainCrosshairPaint(axesColor);
	pp.setRangeCrosshairPaint(axesColor);
	pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	pp.setDomainCrosshairVisible(false);
	pp.setRangeCrosshairVisible(false);

	pp.getDomainAxis().setAxisLinePaint(axesColor);
	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
	}

	NumberAxis axis = (NumberAxis) pp.getRangeAxis();
	axis = formatYAxis(scope, axis);
	pp.setRangeAxis(axis);
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
		pp.setRangeGridlinesVisible(true);
	} else {
		pp.setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());
	}

	// resetAutorange(scope);

	if (getType() == ChartOutput.SERIES_CHART) {
		if (xlabel == null) {
			xlabel = "time";
		}
	}
	if (getType() == ChartOutput.XY_CHART) {}
	if (getType() == ChartOutput.SCATTER_CHART) {}
	if (!this.getXTickValueVisible(scope)) {
		pp.getDomainAxis().setTickMarksVisible(false);
		pp.getDomainAxis().setTickLabelsVisible(false);

	}

}
 
Example #27
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	final XYPlot pp = (XYPlot) chart.getPlot();
	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setDomainCrosshairPaint(axesColor);
	pp.setRangeCrosshairPaint(axesColor);
	pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	pp.setDomainCrosshairVisible(false);
	pp.setRangeCrosshairVisible(false);
	pp.setRangeGridlinesVisible(false);
	pp.setDomainGridlinesVisible(false);

	pp.getDomainAxis().setAxisLinePaint(axesColor);

	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
	}
	if (xtickunit > 0) {
		((NumberAxis) pp.getDomainAxis()).setTickUnit(new NumberTickUnit(xtickunit));
	}

	pp.getRangeAxis().setAxisLinePaint(axesColor);
	pp.getRangeAxis().setLabelFont(getLabelFont());
	pp.getRangeAxis().setTickLabelFont(getTickFont());
	if (textColor != null) {
		pp.getRangeAxis().setLabelPaint(textColor);
		pp.getRangeAxis().setTickLabelPaint(textColor);
	}
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
	}

	// resetAutorange(scope);

	if (xlabel != null && !xlabel.isEmpty()) {
		pp.getDomainAxis().setLabel(xlabel);
	}
	if (ylabel != null && !ylabel.isEmpty()) {
		pp.getRangeAxis().setLabel(ylabel);
	}

}
 
Example #28
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 #29
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 #30
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();
}