Java Code Examples for org.jfree.chart.title.LegendTitle#setItemFont()

The following examples show how to use org.jfree.chart.title.LegendTitle#setItemFont() . 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: TaChart.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructor.
 * @param box a ChartIndicatorBox
 */
public TaChart(IndicatorBox box){
    mapTradingRecordMarker = new HashMap<>();
    this.chartIndicatorBox = box;
    this.chartIndicatorBox.getIndicartors().addListener(this);
    XYDataset candlesBarData = createOHLCDataset(chartIndicatorBox.getBarSeries());
    this.mainPlot = createMainPlot(candlesBarData);
    this.combinedXYPlot = createCombinedDomainXYPlot(mainPlot);
    this.setCache(true);
    this.setCacheHint(CacheHint.SPEED);
    final JFreeChart chart = new JFreeChart(combinedXYPlot);
    TaChartViewer viewer = new TaChartViewer(chart);
    Color chartBackground = Color.WHITE;
    chart.setBackgroundPaint(chartBackground);
    getChildren().add(viewer);
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemFont(new Font("Arial", Font.BOLD, 12));
    Color legendBackground = new Color(0, 0, 0, 0);
    legend.setBackgroundPaint(legendBackground);

    chartIndicatorBox.getObservableBarSeries().addListener((ob, o, n) -> reloadBarSeries(n));
}
 
Example 2
Source File: CommonPieChartAction.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
private void fillChart(String title, List<String> names, 
		List<String> colors, List<Float> values) throws Exception {
	DefaultPieDataset data=new DefaultPieDataset();
	for (int ix=0; ix<names.size(); ix++) {
		data.setValue( names.get(ix), values.get(ix) );
	}
       this.chart=ChartFactory.createPieChart3D(
       		title, 
       		data, 
       		true,
       		true, 
       		false);
       LegendTitle legend=this.chart.getLegend();
       legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9) );
       PiePlot plot=(PiePlot)this.chart.getPlot();
       plot.setCircular(true);
       plot.setBackgroundAlpha(0.9f);       
       plot.setForegroundAlpha(0.5f);
       plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9) );
       this.setPlotColor( plot, names, colors );
       this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9) ) ); 		
}
 
Example 3
Source File: LegendTitleTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the equals() method distinguishes all fields.
 */
public void testEquals() {
    XYPlot plot1 = new XYPlot();
    LegendTitle t1 = new LegendTitle(plot1);
    LegendTitle t2 = new LegendTitle(plot1);
    assertEquals(t1, t2);
    
    t1.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertFalse(t1.equals(t2));
    t2.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertTrue(t1.equals(t2));
    
    t1.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertTrue(t1.equals(t2));
    
    t1.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertTrue(t1.equals(t2));
    
    t1.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertTrue(t1.equals(t2));
    
    t1.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertFalse(t1.equals(t2));
    t2.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertTrue(t1.equals(t2));
}
 
Example 4
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 5
Source File: LegendTitleTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the equals() method distinguishes all fields.
 */
public void testEquals() {
    XYPlot plot1 = new XYPlot();
    LegendTitle t1 = new LegendTitle(plot1);
    LegendTitle t2 = new LegendTitle(plot1);
    assertEquals(t1, t2);

    t1.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertFalse(t1.equals(t2));
    t2.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertTrue(t1.equals(t2));

    t1.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertFalse(t1.equals(t2));
    t2.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertTrue(t1.equals(t2));
}
 
Example 6
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 7
Source File: EStandardChartTheme.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fixes the legend item's colour after the colours of the datasets/series in the plot were
 * changed.
 * 
 * @param chart The chart.
 */
public static void fixLegend(JFreeChart chart) {
  XYPlot plot = chart.getXYPlot();
  LegendTitle oldLegend = chart.getLegend();
  RectangleEdge pos = oldLegend.getPosition();
  chart.removeLegend();
  
  LegendTitle newLegend = new LegendTitle(plot);
  newLegend.setPosition(pos);
  newLegend.setItemFont(oldLegend.getItemFont());
  chart.addLegend(newLegend);
  newLegend.setVisible(oldLegend.isVisible());
}
 
Example 8
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 9
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 10
Source File: SeriesChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void updatePlotter() {
	int categoryCount = prepareData();
	String maxClassesProperty = ParameterService
			.getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
	int maxClasses = 20;
	try {
		if (maxClassesProperty != null) {
			maxClasses = Integer.parseInt(maxClassesProperty);
		}
	} catch (NumberFormatException e) {
		// LogService.getGlobal().log("Series plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
		// LogService.WARNING);
		LogService.getRoot().log(Level.WARNING,
				"com.rapidminer.gui.plotter.charts.SeriesChartPlotter.parsing_property_error");
	}
	boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

	JFreeChart chart = createChart(this.dataset, createLegend);

	// set the background color for the chart...
	chart.setBackgroundPaint(Color.white);

	// domain axis
	if (axis[INDEX] >= 0) {
		if (!dataTable.isNominal(axis[INDEX])) {
			if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) {
				DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX]));
				domainAxis.setTimeZone(Tools.getPreferredTimeZone());
				chart.getXYPlot().setDomainAxis(domainAxis);
				if (getRangeForDimension(axis[INDEX]) != null) {
					domainAxis.setRange(getRangeForDimension(axis[INDEX]));
				}
				domainAxis.setLabelFont(LABEL_FONT_BOLD);
				domainAxis.setTickLabelFont(LABEL_FONT);
				domainAxis.setVerticalTickLabels(isLabelRotating());
			}
		} else {
			LinkedHashSet<String> values = new LinkedHashSet<String>();
			for (DataTableRow row : dataTable) {
				String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX]));
				if (stringValue.length() > 40) {
					stringValue = stringValue.substring(0, 40);
				}
				values.add(stringValue);
			}
			ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]),
					values.toArray(new String[values.size()]));
			categoryAxis.setLabelFont(LABEL_FONT_BOLD);
			categoryAxis.setTickLabelFont(LABEL_FONT);
			categoryAxis.setVerticalTickLabels(isLabelRotating());
			chart.getXYPlot().setDomainAxis(categoryAxis);
		}
	}

	// legend settings
	LegendTitle legend = chart.getLegend();
	if (legend != null) {
		legend.setPosition(RectangleEdge.TOP);
		legend.setFrame(BlockBorder.NONE);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
		legend.setItemFont(LABEL_FONT);
	}

	AbstractChartPanel panel = getPlotterPanel();
	if (panel == null) {
		panel = createPanel(chart);
	} else {
		panel.setChart(chart);
	}

	// ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
	panel.getChartRenderingInfo().setEntityCollection(null);
}
 
Example 11
Source File: XYTitleAnnotationDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        false,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(200, 200, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.BOTTOM);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, 
            RectangleAnchor.BOTTOM_RIGHT);
    
    ta.setMaxWidth(0.48);
    plot.addAnnotation(ta);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setLowerMargin(0.35);
    return chart;

}
 
Example 12
Source File: cfCHART.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
private void setLegend(JFreeChart chart, boolean bShowLegend, Font font, Color foregroundColor, Color backgroundColor, cfCHARTLEGENDData legendData) throws cfmRunTimeException {
	LegendTitle legend = new LegendTitle(chart.getPlot());
	legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));

	// If a CFCHARTLEGEND tag was used then use it's attributes to configure the
	// legend
	if (legendData != null) {
		// A CFCHARTLEGEND tag is present so use its attributes to configure the
		// legend
		legend.setItemFont(getFont(legendData.getFont(), legendData.getFontBold(), legendData.getFontItalic(), legendData.getFontSize()));
		legend.setItemPaint(convertStringToColor(legendData.getLabelColor()));
		legend.setBackgroundPaint(convertStringToColor(legendData.getBackgroundColor()));

		String pos = legendData.getPosition();
		if (pos.equals("top"))
			legend.setPosition(RectangleEdge.TOP);
		else if (pos.equals("bottom"))
			legend.setPosition(RectangleEdge.BOTTOM);
		else if (pos.equals("left"))
			legend.setPosition(RectangleEdge.LEFT);
		else if (pos.equals("right"))
			legend.setPosition(RectangleEdge.RIGHT);

		if (!legendData.getShowBorder())
			legend.setBorder(BlockBorder.NONE);
		else
			legend.setBorder(new BlockBorder());
	} else {
		// A CFCHARTLEGEND tag is NOT present so use the attributes from the
		// CFCHART tag to configure the legend
		if (!bShowLegend)
			return;

		legend.setItemFont(font);
		legend.setItemPaint(foregroundColor);
		legend.setBackgroundPaint(backgroundColor);

		// By default CFMX 7 places the legend at the top with no border
		legend.setPosition(RectangleEdge.TOP);
		legend.setBorder(BlockBorder.NONE);
	}

	// Add the legend to the chart
	chart.addSubtitle(legend);
}
 
Example 13
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 14
Source File: ROCChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(XYDataset dataset) {
	// create the chart...
	JFreeChart chart = ChartFactory.createXYLineChart(null,      // chart title
			null,                      // x axis label
			null,                      // y axis label
			dataset,                  // data
			PlotOrientation.VERTICAL, true,                     // include legend
			true,                     // tooltips
			false                     // urls
			);

	chart.setBackgroundPaint(Color.white);

	// get a reference to the plot for further customisation...
	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.WHITE);
	plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
	plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

	ValueAxis valueAxis = plot.getRangeAxis();
	valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
	valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

	ValueAxis domainAxis = plot.getDomainAxis();
	domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
	domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

	DeviationRenderer renderer = new DeviationRenderer(true, false);
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	if (dataset.getSeriesCount() == 1) {
		renderer.setSeriesStroke(0, stroke);
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);
	} else if (dataset.getSeriesCount() == 2) {
		renderer.setSeriesStroke(0, stroke);
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);

		renderer.setSeriesStroke(1, stroke);
		renderer.setSeriesPaint(1, Color.BLUE);
		renderer.setSeriesFillPaint(1, Color.BLUE);
	} else {
		for (int i = 0; i < dataset.getSeriesCount(); i++) {
			renderer.setSeriesStroke(i, stroke);
			Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
			renderer.setSeriesPaint(i, color);
			renderer.setSeriesFillPaint(i, color);
		}
	}
	renderer.setAlpha(0.12f);
	plot.setRenderer(renderer);

	// legend settings
	LegendTitle legend = chart.getLegend();
	if (legend != null) {
		legend.setPosition(RectangleEdge.TOP);
		legend.setFrame(BlockBorder.NONE);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
		legend.setItemFont(PlotterAdapter.LABEL_FONT);
	}
	return chart;
}
 
Example 15
Source File: ParetoChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public void paintParetoChart(Graphics graphics) {
	prepareData();

	JFreeChart chart = createChart();

	if (chart != null) {
		// set the background color for the chart...
		chart.setBackgroundPaint(Color.white);
		chart.getPlot().setBackgroundPaint(Color.WHITE);

		// bar renderer --> own 3D effect
		CategoryPlot plot = chart.getCategoryPlot();
		BarRenderer renderer = (BarRenderer) plot.getRenderer();
		// renderer.setBarPainter(new StandardBarPainter());
		renderer.setBarPainter(new RapidBarPainter());

		renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1));

		// labels on top of bars
		Map<String, String> barItemLabels = new HashMap<>();
		Map<String, String> cumulativeItemLabels = new HashMap<>();
		int groupSum = 0;
		int totalSum = 0;
		for (Object key : totalData.getKeys()) {
			String k = (String) key;
			try {
				Number groupValue = data.getValue(k);
				Number totalValue = totalData.getValue(k);
				groupSum += groupValue.intValue();
				totalSum += totalValue.intValue();
				barItemLabels.put(
						k,
						Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / "
								+ Tools.formatIntegerIfPossible(totalValue.doubleValue()));
				cumulativeItemLabels.put(k, groupSum + " / " + totalSum);
			} catch (UnknownKeyException e) {
				// do nothing
			}
		}
		renderer.setSeriesItemLabelFont(0, LABEL_FONT);

		if (showBarLabelsFlag) {
			renderer.setSeriesItemLabelsVisible(0, true);
			renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels));

			if (isLabelRotating()) {
				renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
						TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
				renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
						TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
			}
		}

		LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1);
		renderer2.setSeriesPaint(0, Color.GRAY.darker().darker());
		renderer2.setSeriesItemLabelFont(0, LABEL_FONT);
		renderer2.setSeriesItemLabelPaint(0, Color.BLACK);
		if (isLabelRotating()) {
			renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
					TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
			renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
					TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
		} else {
			renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10,
					TextAnchor.BOTTOM_RIGHT));
			renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10,
					TextAnchor.BOTTOM_RIGHT));
		}

		if (showCumulativeLabelsFlag) {
			renderer2.setSeriesItemLabelsVisible(0, true);
			renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels));
		}

		// draw outlines
		renderer.setDrawBarOutline(true);

		// gridline colors
		plot.setRangeGridlinePaint(Color.BLACK);

		// legend settings
		LegendTitle legend = chart.getLegend();
		if (legend != null) {
			legend.setPosition(RectangleEdge.TOP);
			legend.setFrame(BlockBorder.NONE);
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
			legend.setItemFont(LABEL_FONT);
		}

		Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
		chart.draw((Graphics2D) graphics, drawRect);
	}
}
 
Example 16
Source File: WebPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void updatePlotter() {
	final int categoryCount = prepareData();

	SwingUtilities.invokeLater(new Runnable() {

		@Override
		public void run() {
			scrollablePlotterPanel.remove(viewScrollBar);
		}
	});

	if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				viewScrollBar.setOrientation(Adjustable.HORIZONTAL);
				scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH);
			}
		});

		this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT);
		viewScrollBar.setMaximum(categoryCount);
		viewScrollBar.setValue(0);

	} else {
		this.slidingCategoryDataSet = null;
	}

	if (categoryCount <= MAX_CATEGORIES) {

		SpiderWebPlot plot = new SpiderWebPlot(categoryDataSet);

		plot.setAxisLinePaint(Color.LIGHT_GRAY);
		plot.setOutlinePaint(Color.WHITE);

		plot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

		JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, true);

		double[] colorValues = null;
		if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) {
			colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)];
		} else {
			colorValues = new double[categoryDataSet.getColumnCount()];
		}
		for (int i = 0; i < colorValues.length; i++) {
			colorValues[i] = i;
		}

		if (panel != null) {
			panel.setChart(chart);
		} else {
			panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
			scrollablePlotterPanel.add(panel, BorderLayout.CENTER);
			final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
			panel.addMouseListener(controller);
			panel.addMouseMotionListener(controller);
		}

		// set the background color for the chart...
		chart.setBackgroundPaint(Color.white);

		// legend settings
		LegendTitle legend = chart.getLegend();
		if (legend != null) {
			legend.setPosition(RectangleEdge.TOP);
			legend.setFrame(BlockBorder.NONE);
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
			legend.setItemFont(LABEL_FONT);
		}
		if (groupByColumn < 0) {
			// no legend is needed when there is no group-by selection
			chart.removeLegend();
		}
		// ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
		panel.getChartRenderingInfo().setEntityCollection(null);
	} else {
		LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns",
				new Object[] { categoryCount, MAX_CATEGORIES });
	}
}
 
Example 17
Source File: AbstractPieChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public void updatePlotter() {
	int categoryCount = prepareData();
	String maxClassesProperty = ParameterService
			.getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT);
	int maxClasses = 20;
	try {
		if (maxClassesProperty != null) {
			maxClasses = Integer.parseInt(maxClassesProperty);
		}
	} catch (NumberFormatException e) {
		// LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
		// LogService.WARNING);
		LogService.getRoot().log(Level.WARNING,
				"com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error");
	}
	boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

	if (categoryCount <= MAX_CATEGORIES) {
		JFreeChart chart = createChart(pieDataSet, createLegend);

		// set the background color for the chart...
		chart.setBackgroundPaint(Color.white);

		PiePlot plot = (PiePlot) chart.getPlot();

		plot.setBackgroundPaint(Color.WHITE);
		plot.setSectionOutlinesVisible(true);
		plot.setShadowPaint(new Color(104, 104, 104, 100));

		int size = pieDataSet.getKeys().size();
		for (int i = 0; i < size; i++) {
			Comparable<?> key = pieDataSet.getKey(i);
			plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1)));

			boolean explode = false;
			for (String explosionGroup : explodingGroups) {
				if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) {
					explode = true;
					break;
				}
			}

			if (explode) {
				plot.setExplodePercent(key, this.explodingAmount);
			}
		}

		plot.setLabelFont(LABEL_FONT);
		plot.setNoDataMessage("No data available");
		plot.setCircular(true);
		plot.setLabelGap(0.02);
		plot.setOutlinePaint(Color.WHITE);

		// legend settings
		LegendTitle legend = chart.getLegend();
		if (legend != null) {
			legend.setPosition(RectangleEdge.TOP);
			legend.setFrame(BlockBorder.NONE);
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
			legend.setItemFont(LABEL_FONT);
		}

		if (panel instanceof AbstractChartPanel) {
			panel.setChart(chart);
		} else {
			panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
			final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
			panel.addMouseListener(controller);
			panel.addMouseMotionListener(controller);
		}

		// ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
		panel.getChartRenderingInfo().setEntityCollection(null);
	} else {
		// LogService.getGlobal().logNote("Too many columns (" + categoryCount +
		// "), this chart is only able to plot up to " + MAX_CATEGORIES +
		// " different categories.");
		LogService.getRoot().log(Level.INFO,
				"com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns",
				new Object[] { categoryCount, MAX_CATEGORIES });
	}
}
 
Example 18
Source File: StatsGraphServlet.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
		ServletException {
	String action = WebUtils.getString(request, "action", "graph");
	String type = WebUtils.getString(request, "t");
	JFreeChart chart = null;
	updateSessionManager(request);

	try {
		if ("refresh".equals(action)) {
			new RepositoryInfo().runAs(null);
			ServletContext sc = getServletContext();
			sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
		} else {
			response.setContentType("image/png");
			OutputStream out = response.getOutputStream();

			if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
				chart = repoStats(type);
			} else if (DISK.equals(type)) {
				chart = diskStats();
			} else if (JVM_MEMORY.equals(type)) {
				chart = jvmMemStats();
			} else if (OS_MEMORY.equals(type)) {
				chart = osMemStats();
			}

			if (chart != null) {
				// Customize title font
				chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

				// Match body {	background-color:#F6F6EE; }
				chart.setBackgroundPaint(new Color(246, 246, 238));

				// Customize no data
				PiePlot plot = (PiePlot) chart.getPlot();
				plot.setNoDataMessage("No data to display");

				// Customize labels
				plot.setLabelGenerator(null);

				// Customize legend
				LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
				legend.setPosition(RectangleEdge.BOTTOM);
				legend.setFrame(BlockBorder.NONE);
				legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
				chart.removeLegend();
				chart.addLegend(legend);

				if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
					ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
				} else {
					ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
				}
			}

			out.flush();
			out.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 19
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected void configureChart(JFreeChart jfreeChart) throws JRException
{
	if (getChart().getModeValue() == ModeEnum.OPAQUE)
	{
		jfreeChart.setBackgroundPaint(getChart().getBackcolor());
	}
	else
	{
		jfreeChart.setBackgroundPaint(null);
	}
	
	RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP);
	
	if (jfreeChart.getTitle() != null)
	{
		TextTitle title = jfreeChart.getTitle();
		title.setPaint(getChart().getTitleColor());

		title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale()));
		title.setPosition(titleEdge);
	}

	String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
	if (subtitleText != null)
	{
		TextTitle subtitle = new TextTitle(subtitleText);
		subtitle.setPaint(getChart().getSubtitleColor());

		subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale()));
		subtitle.setPosition(titleEdge);

		jfreeChart.addSubtitle(subtitle);
	}

	// Apply all of the legend formatting options
	LegendTitle legend = jfreeChart.getLegend();
	if (legend != null)
	{
		legend.setItemPaint(getChart().getLegendColor());

		if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless
		{
			legend.setBackgroundPaint(null);
		}
		else
		{
			legend.setBackgroundPaint(getChart().getLegendBackgroundColor());
		}

		legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale()));
		legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM));
	}
	
	configurePlot(jfreeChart.getPlot());
}
 
Example 20
Source File: HistogramChart.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public HistogramChart() {
  super(ChartFactory.createHistogram("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  ));

  // initialize the chart by default time series chart from factory
  chart = getChart();

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

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