org.jfree.chart.ui.TextAnchor Java Examples

The following examples show how to use org.jfree.chart.ui.TextAnchor. 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: ScatterHome.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
private void makeDataLabels( Set<Report> toolResults, XYPlot xyplot ) {        
    HashMap<Point2D,String> map = makePointList( toolResults );
    for (Entry<Point2D,String> e : map.entrySet() ) {
        if ( e.getValue() != null ) {
            Point2D p = e.getKey();
            String label = sort( e.getValue() );
            XYTextAnnotation annotation = new XYTextAnnotation( label, p.getX(), p.getY());
            annotation.setTextAnchor( p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            if (label.toCharArray()[0] == averageLabel)
            {
                annotation.setPaint(Color.magenta);
            } else {
                annotation.setPaint(Color.blue);
            }
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }
    }
}
 
Example #2
Source File: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
public static void makePointer(XYPlot plot, double x, double y, String msg, TextAnchor anchor, int angle ) {
//        TextTitle textTitle = new TextTitle(msg, theme.getSmallFont(), Color.red, RectangleEdge.TOP, HorizontalAlignment.LEFT, VerticalAlignment.TOP, new RectangleInsets(2, 2, 2, 2));
//        XYTitleAnnotation title = new XYTitleAnnotation(x/100, y/100, textTitle, RectangleAnchor.TOP_LEFT);
//        plot.addAnnotation( title );
        
        XYPointerAnnotation pointer = new XYPointerAnnotation(msg, x, y, Math.toRadians(angle));
        pointer.setBackgroundPaint(Color.white);
        pointer.setTextAnchor(anchor);
        pointer.setArrowWidth(4);
        pointer.setArrowLength(8);
        pointer.setArrowPaint(Color.red);
        pointer.setLabelOffset(2);
        pointer.setPaint(Color.red);
        pointer.setFont(theme.getRegularFont());
        plot.addAnnotation(pointer);;
    }
 
Example #3
Source File: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
public static void makeGuessingLine(XYPlot xyplot) {
    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 100, 100, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(80, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);
}
 
Example #4
Source File: ScatterVulns.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
private void makeDataLabels(String category, Set<Report> toolResults, XYPlot xyplot) {
    HashMap<Point2D, String> map = makePointList(category, toolResults);
    for (Entry<Point2D, String> e : map.entrySet()) {
        if (e.getValue() != null) {
            Point2D p = e.getKey();
            String label = sort(e.getValue());
            XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
            annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            if (label.toCharArray()[0] == averageLabel) {
                annotation.setPaint(Color.magenta);
            } else {
                annotation.setPaint(Color.blue);
            }
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }
    }
}
 
Example #5
Source File: ScatterTools.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
private void makeDataLabels(OverallResults or, XYPlot xyplot) {
	HashMap<Point2D, String> map = makePointList(or);
	for (Entry<Point2D, String> e : map.entrySet()) {
		if (e.getValue() != null) {
			Point2D p = e.getKey();
			String label = sort(e.getValue());
			XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
			annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
			annotation.setBackgroundPaint(Color.white);
			// set color of average to black and everything else to blue
			if(averageLabel==label.toCharArray()[0]){
				annotation.setPaint(Color.magenta);
			} else {
			    annotation.setPaint(Color.blue);
			}
			annotation.setFont(theme.getRegularFont());
			xyplot.addAnnotation(annotation);
		}
	}
}
 
Example #6
Source File: ScatterInterpretation.java    From Benchmark with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart display(String title, int height ) {

        XYSeriesCollection dataset = new XYSeriesCollection();
        chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false);
        theme.apply(chart);

        XYPlot xyplot = chart.getXYPlot();
        initializePlot( xyplot );
        
        makePointer( xyplot, 7, 93, " Ideal vulnerability detection", TextAnchor.TOP_LEFT, 45 );
        makePointer( xyplot, 10, 10, " Tool reports nothing is vulnerable", TextAnchor.TOP_LEFT, 45 );
        // makePointer( xyplot, 70, 30, " Worse than random", TextAnchor.TOP_LEFT, 45 );
        makePointer( xyplot, 90, 90, "Tool reports everything is vulnerable ", TextAnchor.TOP_LEFT, 45);
        makePointer( xyplot, 50, 50, "Tool reports vulnerabilities randomly ", TextAnchor.TOP_LEFT, 45);

        makeOval( xyplot, 0, 3, 20, 10, 45 );
        makeOval( xyplot, 42, 3, 20, 10, 45 );
        makeOval( xyplot, 84, 3, 20, 10, 45 );
        makeOval( xyplot, 43, 64, 20, 10, 45 );

        return chart;
    }
 
Example #7
Source File: MouseListenerTimelapse.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected ValueMarker makeMarker( final int timePoint )
{
	final ValueMarker valueMarker = new ValueMarker( timePoint );
	valueMarker.setStroke( new BasicStroke ( 1.5f ) );
	valueMarker.setPaint( new Color( 0.0f, 93f/255f, 9f/255f ) );
	valueMarker.setLabel( " Reference\n Timepoint " + timePoint );
	valueMarker.setLabelAnchor(RectangleAnchor.BOTTOM );
	valueMarker.setLabelTextAnchor( TextAnchor.BOTTOM_LEFT );
	
	return valueMarker;
}
 
Example #8
Source File: MouseListenerTimelapse.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected ValueMarker makeMarker( final int timePoint )
{
	final ValueMarker valueMarker = new ValueMarker( timePoint );
	valueMarker.setStroke( new BasicStroke ( 1.5f ) );
	valueMarker.setPaint( new Color( 0.0f, 93f/255f, 9f/255f ) );
	valueMarker.setLabel( " Reference\n Timepoint " + timePoint );
	valueMarker.setLabelAnchor(RectangleAnchor.BOTTOM );
	valueMarker.setLabelTextAnchor( TextAnchor.BOTTOM_LEFT );
	
	return valueMarker;
}
 
Example #9
Source File: MouseListenerValue.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected ValueMarker makeMarker( final double value )
{
	final ValueMarker valueMarker = new ValueMarker( value );
	valueMarker.setStroke( new BasicStroke ( 2f ) );
	valueMarker.setPaint( new Color( 0f/255f, 0f/255f, 255f/255f ) );
	valueMarker.setLabel( " Distance=" + value );
	valueMarker.setLabelPaint( Color.BLUE );
	valueMarker.setLabelAnchor( RectangleAnchor.TOP );
	valueMarker.setLabelTextAnchor( TextAnchor.TOP_LEFT );

	return valueMarker;
}
 
Example #10
Source File: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
public static void addGenerationDate(XYPlot xyplot) {
    //add scorecard generation date
    final String pattern = "dd MMM yyyy h:mm a";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    String date = simpleDateFormat.format(new Date());
    XYTextAnnotation gendate = new XYTextAnnotation("Scorecard Generated: " + date, 0.5, -7.5);
    gendate.setTextAnchor(TextAnchor.CENTER_LEFT);
    gendate.setBackgroundPaint(Color.white);
    gendate.setPaint(Color.red);
    gendate.setFont(theme.getRegularFont());
    xyplot.addAnnotation( gendate );
}
 
Example #11
Source File: ScatterPlot.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
public static XYPointerAnnotation makePointer(int x, int y, String msg, TextAnchor anchor, int angle ) {
    XYPointerAnnotation pointer = new XYPointerAnnotation(msg, x, y, Math.toRadians(angle));
    pointer.setBackgroundPaint(Color.white);
    pointer.setTextAnchor(anchor);
    pointer.setArrowWidth(4);
    pointer.setArrowLength(8);
    pointer.setArrowPaint(Color.red);
    pointer.setLabelOffset(2);
    pointer.setPaint(Color.red);
    pointer.setFont(theme.getRegularFont());
    return pointer;
}
 
Example #12
Source File: ScatterTools.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
private JFreeChart display(String title, int height, OverallResults or) {

		XYSeriesCollection dataset = new XYSeriesCollection();
		XYSeries series = new XYSeries("Scores");
		int totalTools = 0;
		double totalToolTPR = 0;
		double totalToolFPR = 0;
		for (OverallResult r : or.getResults()) {	
			series.add(r.falsePositiveRate * 100, r.truePositiveRate * 100);
			totalTools++;
			totalToolTPR += r.truePositiveRate;
			totalToolFPR += r.falsePositiveRate;
		}
		atpr = totalToolTPR / totalTools;
		afpr = totalToolFPR / totalTools;
		
		if ( or.getResults().size() > 1) {
		    series.add(afpr * 100, atpr * 100);
		}

		dataset.addSeries(series);

		chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false);
        theme.apply(chart);

		XYPlot xyplot = chart.getXYPlot();

		initializePlot( xyplot );

		makeDataLabels(or, xyplot);
		makeLegend( or, 103, 93, dataset, xyplot );

		XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6);
		time.setTextAnchor(TextAnchor.TOP_LEFT);
		time.setFont(theme.getRegularFont());
		time.setPaint(Color.red);
		xyplot.addAnnotation(time);

		return chart;
	}
 
Example #13
Source File: VanKrevelenDiagramTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
  logger.info("Creating new 2D chart instance");
  appliedSteps++;

  // load dataset
  VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);

  // create chart
  chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL,
      true, true, false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setBackgroundPaint(Color.WHITE);
  plot.setDomainCrosshairPaint(Color.GRAY);
  plot.setRangeCrosshairPaint(Color.GRAY);
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  appliedSteps++;

  // set renderer
  XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

  // calc block sizes
  double maxX = plot.getDomainAxis().getRange().getUpperBound();
  double maxY = plot.getRangeAxis().getRange().getUpperBound();

  renderer.setBlockWidth(0.001);
  renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));

  // set tooltip generator
  ScatterPlotToolTipGenerator tooltipGenerator =
      new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
  renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
  plot.setRenderer(renderer);

  // set item label generator
  NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
  renderer.setDefaultItemLabelGenerator(generator);
  renderer.setDefaultItemLabelsVisible(false);
  renderer.setDefaultItemLabelFont(legendFont);
  renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
      TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);

  return chart;
}
 
Example #14
Source File: KendrickMassPlotTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameterSet);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}
 
Example #15
Source File: JPanelProfil.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update the profil chart
 */
public void RefreshProfilChart() {
	if (track == null)
		return;
	if (track.data.isEmpty())
		return;

	// -- Clear all series
	if (datasetProfil.getSeriesCount() > 0)
		datasetProfil.removeAllSeries();

	XYPlot plot = chartProfil.getXYPlot();
	plot.clearDomainMarkers();

	// -- Populate the serie
	XYSeries serie1 = new XYSeries("Elevation/Distance");
	int cmpt = 1;
	for (CgData r : track.data) {
		double x = r.getTotal(settings.Unit) / 1000;
		double y = r.getElevation(settings.Unit);
		serie1.add(x, y);

		if (((r.getTag() & CgConst.TAG_MARK) != 0) & showProfilMarker) {
			Marker m = new ValueMarker(x);
			m.setPaint(Color.GRAY);
			m.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
			m.setLabel(String.valueOf(cmpt));
			m.setLabelOffset(new RectangleInsets(5, 0, 0, 2));
			m.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
			m.setLabelTextAnchor(TextAnchor.TOP_LEFT);
			plot.addDomainMarker(m);
			cmpt++;
		}
	}
	datasetProfil.addSeries(serie1);

	if (track.getMaxElev(settings.Unit) > track.getMinElev(settings.Unit)) {
		// XYPlot plot = chart.getXYPlot();
		ValueAxis axisY = plot.getRangeAxis();
		axisY.setRange(Math.floor(track.getMinElev(settings.Unit) / 100.0) * 100.0,
				Math.ceil(track.getMaxElev(settings.Unit) / 100.0) * 100.0);
	}
}
 
Example #16
Source File: ChartJFreeChartOutputHistogram.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
protected void resetRenderer(final IScope scope, final String serieid) {
	// AbstractCategoryItemRenderer
	// newr=(AbstractCategoryItemRenderer)this.getOrCreateRenderer(scope,
	// serieid);
	final CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
	final AbstractCategoryItemRenderer newr = (AbstractCategoryItemRenderer) plot.getRenderer();
	// if
	// (serieid!=this.getChartdataset().series.keySet().iterator().next())
	// newr=(AbstractCategoryItemRenderer)this.getOrCreateRenderer(scope,
	// serieid);

	final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);
	if (!IdPosition.containsKey(serieid)) {
		// DEBUG.LOG("pb!!!");
	} else {
		final int myrow = IdPosition.get(serieid);
		if (myserie.getMycolor() != null) {
			newr.setSeriesPaint(myrow, myserie.getMycolor());
		}

		if (this.series_label_position.equals("onchart")) {
			// ((BarRenderer)newr).setBaseItemLabelGenerator(new
			// LabelGenerator());
			newr.setDefaultItemLabelGenerator(new LabelGenerator());
			final ItemLabelPosition itemlabelposition =
					new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
			newr.setDefaultPositiveItemLabelPosition(itemlabelposition);
			newr.setDefaultNegativeItemLabelPosition(itemlabelposition);
			newr.setDefaultItemLabelsVisible(true);
		}

		if (newr instanceof BarRenderer) {
			if (gap >= 0) {
				((BarRenderer) newr).setMaximumBarWidth(1 - gap);

			}

		}
	}

}
 
Example #17
Source File: NumberLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public NumberLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Request",
				"Hit Rate", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setTickUnit(new NumberTickUnit(500));
//		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAutoRangeIncludesZero(true);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(0.2));
		numberAxisY.setRangeWithMargins(0,1);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		// ����Y������Ϊ�ٷֱ�
		numberAxisY.setNumberFormatOverride(NumberFormat.getPercentInstance());
		
		
		
		XYItemRenderer xyitem = plot.getRenderer();   
        xyitem.setDefaultItemLabelsVisible(true);
//        ItemLabelsVisible(true);

		xyitem.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 12));
		xyitem.setDefaultItemLabelFont(new Font("Dialog", 1, 12));
        plot.setRenderer(xyitem);
		
		 	XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
			renderer.setDefaultItemLabelsVisible(true);
			renderer.setDefaultShapesVisible(true);
			renderer.setDrawOutlines(true);
			
			renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));


			
			renderer.setSeriesPaint(0, Color.RED);
			renderer.setSeriesPaint(1, new Color(53,101,253));
			renderer.setSeriesPaint(2, new Color(0,161,59));//����ɫ
			renderer.setSeriesPaint(3, new Color(148,103,189));//��ɫ
			

			renderer.setSeriesStroke(0, new BasicStroke(4.0F));
			renderer.setSeriesStroke(1, new BasicStroke(4.0F));
			renderer.setSeriesStroke(2, new BasicStroke(4.0F));
			renderer.setSeriesStroke(3, new BasicStroke(4.0F));
			renderer.setSeriesStroke(4, new BasicStroke(2.0F));
			renderer.setSeriesStroke(5, new BasicStroke(2.0F));
		
			this.chartFrame = new ChartFrame("Line Chart", chart);
			chartFrame.pack();
			chartFrame.setSize(1600,1200);
			chartFrame.setLocation(300,200);
			chartFrame.setVisible(true);
	}
 
Example #18
Source File: VanKrevelenDiagramTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
  logger.info("Creating new 2D chart instance");
  appliedSteps++;

  // load dataset
  VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);

  // create chart
  chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL,
      true, true, false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setBackgroundPaint(Color.WHITE);
  plot.setDomainCrosshairPaint(Color.GRAY);
  plot.setRangeCrosshairPaint(Color.GRAY);
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  appliedSteps++;

  // set renderer
  XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

  // calc block sizes
  double maxX = plot.getDomainAxis().getRange().getUpperBound();
  double maxY = plot.getRangeAxis().getRange().getUpperBound();

  renderer.setBlockWidth(0.001);
  renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));

  // set tooltip generator
  ScatterPlotToolTipGenerator tooltipGenerator =
      new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
  renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
  plot.setRenderer(renderer);

  // set item label generator
  NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
  renderer.setDefaultItemLabelGenerator(generator);
  renderer.setDefaultItemLabelsVisible(false);
  renderer.setDefaultItemLabelFont(legendFont);
  renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
      TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);

  return chart;
}
 
Example #19
Source File: KendrickMassPlotTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameters);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}