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

The following examples show how to use org.jfree.chart.JFreeChart#setTitle() . 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: PanamaHitek_SingleDialChart.java    From PanamaHitek_Arduino with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void buildChart2() {
    dataset = new DefaultValueDataset(0);
    DialPlot dialplot = new DialPlot();
    dialplot.setView(0.20D, 0.0D, 0.6D, 0.3D);
    dialplot.setDataset(dataset);
    ArcDialFrame arcdialframe = new ArcDialFrame(60D, 60D);
    arcdialframe.setInnerRadius(0.6D);
    arcdialframe.setOuterRadius(0.9D);
    arcdialframe.setForegroundPaint(Color.darkGray);
    arcdialframe.setStroke(new BasicStroke(3F));
    dialplot.setDialFrame(arcdialframe);
    GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(240, 240, 240));
    DialBackground dialbackground = new DialBackground(gradientpaint);
    dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialplot.addLayer(dialbackground);
    StandardDialScale standarddialscale = new StandardDialScale(chartBottonLimit, chartTopLimit, 115D, -50D, majorDivisions, minorDivisions);
    standarddialscale.setTickRadius(0.88D);
    standarddialscale.setTickLabelOffset(0.07D);
    dialplot.addScale(0, standarddialscale);
    org.jfree.chart.plot.dial.DialPointer.Pin pin = new org.jfree.chart.plot.dial.DialPointer.Pin();
    pin.setRadius(0.8D);
    dialplot.addLayer(pin);
    JFreeChart jfreechart = new JFreeChart(dialplot);
    jfreechart.setTitle(chartTitle);
    add(new ChartPanel(jfreechart));
}
 
Example 2
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@Transactional( readOnly = true )
public JFreeChart getJFreeChart( String name, PlotOrientation orientation, CategoryLabelPositions labelPositions,
    Map<String, Double> categoryValues )
{
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for ( Entry<String, Double> entry : categoryValues.entrySet() )
    {
        dataSet.addValue( entry.getValue(), name, entry.getKey() );
    }

    CategoryPlot plot = getCategoryPlot( dataSet, getBarRenderer(), orientation, labelPositions );

    JFreeChart jFreeChart = getBasicJFreeChart( plot );
    jFreeChart.setTitle( name );

    return jFreeChart;
}
 
Example 3
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setChartTitle() {
	JFreeChart chart = getCurrentChart();
	if (chart != null) {
		String text = plotInstance.getCurrentPlotConfigurationClone().getTitleText();
		if (text == null) {
			chart.setTitle(text);
			return;
		}

		Font font = plotInstance.getCurrentPlotConfigurationClone().getTitleFont();
		if (font == null) {
			font = FontTools.getFont(Font.DIALOG, Font.PLAIN, 10);
		}

		TextTitle textTitle = new TextTitle(text, font);
		textTitle.setPaint(plotInstance.getCurrentPlotConfigurationClone().getTitleColor());

		chart.setTitle(textTitle);

	}

}
 
Example 4
Source File: SimpleBox.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public JFreeChart createChart(DatasetMap datasetMap) {

		BoxAndWhiskerCategoryDataset dataset=(BoxAndWhiskerCategoryDataset)datasetMap.getDatasets().get("1"); 

		JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(
				name, categoryLabel, valueLabel, dataset, 
				false);

		TextTitle title =setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}
		
		CategoryPlot plot = (CategoryPlot) chart.getPlot();
		BoxAndWhiskerRenderer renderer=(BoxAndWhiskerRenderer)plot.getRenderer();
		chart.setBackgroundPaint(Color.white);

		plot.setBackgroundPaint(new Color(Integer.decode("#c0c0c0").intValue()));
		plot.setDomainGridlinePaint(Color.WHITE);
		plot.setDomainGridlinesVisible(true);
		plot.setRangeGridlinePaint(Color.white);
		renderer.setFillBox(true);
		renderer.setArtifactPaint(Color.BLACK);
		renderer.setSeriesPaint(0,new Color(Integer.decode("#0000FF").intValue()));

		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
		rangeAxis.setRange(min, max);

		return chart;
	}
 
Example 5
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setChartTitle(JFreeChart jfreeChart)
{
	TitleSettings titleSettings =  getTitleSettings();
	Boolean showTitle = titleSettings.getShowTitle();
	if (showTitle == null || showTitle)
	{
		TextTitle title = jfreeChart.getTitle();
				
		if (title != null)
		{
			Paint forePaint = getChart().getOwnTitleColor();
			if (forePaint == null && titleSettings.getForegroundPaint() != null)
			{
				forePaint = titleSettings.getForegroundPaint().getPaint();
			}
			if (forePaint == null)
			{
				forePaint = getChart().getTitleColor();
			}
			RectangleEdge titleEdge = getEdge(
					getChart().getTitlePositionValue(), 
					getEdge(
						titleSettings.getPositionValue(), 
						RectangleEdge.TOP
						)
					);
			
			handleTitleSettings(title, titleSettings, getChart().getTitleFont(), forePaint, titleEdge);
		}
	}
	else
	{
		jfreeChart.setTitle((TextTitle)null);
	}
}
 
Example 6
Source File: PanamaHitek_SingleDialChart.java    From PanamaHitek_Arduino with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void buildChart3() {
    dataset = new DefaultValueDataset(0);
    DialPlot dialplot = new DialPlot();
    dialplot.setView(0.78D, 0.37D, 0.22D, 0.26D);
    dialplot.setDataset(dataset);
    ArcDialFrame arcdialframe = new ArcDialFrame(-10D, 20D);
    arcdialframe.setInnerRadius(0.7D);
    arcdialframe.setOuterRadius(0.9D);
    arcdialframe.setForegroundPaint(Color.darkGray);
    arcdialframe.setStroke(new BasicStroke(3F));
    dialplot.setDialFrame(arcdialframe);
    GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(240, 240, 240));
    DialBackground dialbackground = new DialBackground(gradientpaint);
    dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialplot.addLayer(dialbackground);
    StandardDialScale standarddialscale = new StandardDialScale(chartBottonLimit, chartTopLimit, -8D, 16D, majorDivisions, minorDivisions);
    standarddialscale.setTickRadius(0.8D);
    standarddialscale.setTickLabelOffset(-0.041D);
    standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
    dialplot.addScale(0, standarddialscale);
    org.jfree.chart.plot.dial.DialPointer.Pin pin = new org.jfree.chart.plot.dial.DialPointer.Pin();
    pin.setRadius(0.84D);
    dialplot.addLayer(pin);
    JFreeChart jfreechart = new JFreeChart(dialplot);
    jfreechart.setTitle(chartTitle);
    add(new ChartPanel(jfreechart));
}
 
Example 7
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets all the format options on the given chart like fonts, chart title, legend, legend
 * position etc.
 */
private void formatChart(JFreeChart chart) {
	Plot plot = chart.getPlot();
	PlotConfiguration currentPlotConfigurationClone = plotInstance.getCurrentPlotConfigurationClone();

	// set plot background color
	plot.setBackgroundPaint(currentPlotConfigurationClone.getPlotBackgroundColor());

	formatLegend(chart);

	// set chart background color
	chart.setBackgroundPaint(currentPlotConfigurationClone.getChartBackgroundColor());

	// add title to chart
	String text = currentPlotConfigurationClone.getTitleText();
	if (text == null) {
		chart.setTitle(text);
	} else {
		Font font = currentPlotConfigurationClone.getTitleFont();
		if (font == null) {
			font = FontTools.getFont(Font.DIALOG, Font.PLAIN, 10);
		}

		TextTitle textTitle = new TextTitle(text, font);
		textTitle.setPaint(currentPlotConfigurationClone.getTitleColor());

		chart.setTitle(textTitle);
	}
}
 
Example 8
Source File: JFreeChartTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for title changes and event notification.
 */
public void testTitleChangeEvent() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset, true);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    TextTitle t = chart.getTitle();
    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    // now create a new title and replace the existing title, several
    // things should happen:
    // (1) Adding the new title should trigger an immediate
    //     ChartChangeEvent;
    // (2) Modifying the new title should trigger a ChartChangeEvent;
    // (3) Modifying the old title should NOT trigger a ChartChangeEvent
    TextTitle t2 = new TextTitle("T2");
    chart.setTitle(t2);
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    t2.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
}
 
Example 9
Source File: JFreeChartTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for title changes and event notification.
 */
public void testTitleChangeEvent() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, 
            false, false);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    TextTitle t = chart.getTitle();
    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
    
    // now create a new title and replace the existing title, several
    // things should happen:
    // (1) Adding the new title should trigger an immediate 
    //     ChartChangeEvent;
    // (2) Modifying the new title should trigger a ChartChangeEvent;
    // (3) Modifying the old title should NOT trigger a ChartChangeEvent
    TextTitle t2 = new TextTitle("T2");
    chart.setTitle(t2);
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
    
    t2.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
    
    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
}
 
Example 10
Source File: SBISpeedometer.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
	 * Creates a chart of type speedometer.
	 * 
	 * @param chartTitle  the chart title.
	 * @param dataset  the dataset.
	 * 
	 * @return A chart speedometer.
	 */

	public JFreeChart createChart(DatasetMap datasets) {
		logger.debug("IN");
		Dataset dataset=(Dataset)datasets.getDatasets().get("1");

		DialPlot plot = new DialPlot();
		plot.setDataset((ValueDataset)dataset);
		plot.setDialFrame(new StandardDialFrame());

		plot.setBackground(new DialBackground());
		if(dialtextuse){
			DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext);			
			annotation1.setFont(styleTitle.getFont());
			annotation1.setRadius(0.7);

			plot.addLayer(annotation1);
		}

		DialValueIndicator dvi = new DialValueIndicator(0);
		dvi.setFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));
		dvi.setPaint(labelsValueStyle.getColor());
		plot.addLayer(dvi);

		StandardDialScale scale = new StandardDialScale(lower, 
				upper, -120, -300, 10.0, 4);

		if (!( increment > 0)){
			logger.warn("increment cannot be less than 0, put default to 0.1");
			increment = 0.01;
		}

		scale.setMajorTickIncrement(increment);

//		if (!( minorTickCount > 0)){
//			logger.warn("minor tick count cannot be less than 0, put default to 1");
//			minorTickCount = 1;
//		}

		scale.setMinorTickCount(minorTickCount);
		scale.setTickRadius(0.88);
		scale.setTickLabelOffset(0.15);
		//set tick label style
		Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
		scale.setTickLabelFont(tickLabelsFont);
		scale.setTickLabelPaint(labelsTickStyle.getColor());
		plot.addScale(0, scale);

		plot.addPointer(new DialPointer.Pin());

		DialCap cap = new DialCap();
		plot.setCap(cap);

		// sets intervals
		for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
			KpiInterval interval = (KpiInterval) iterator.next();
			StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), 
					interval.getColor()); 
			range.setInnerRadius(0.52);
			range.setOuterRadius(0.55);
			plot.addLayer(range);

		}

		GradientPaint gp = new GradientPaint(new Point(), 
				new Color(255, 255, 255), new Point(), 
				new Color(170, 170, 220));
		DialBackground db = new DialBackground(gp);
		db.setGradientPaintTransformer(new StandardGradientPaintTransformer(
				GradientPaintTransformType.VERTICAL));
		plot.setBackground(db);

		plot.removePointer(0);
		DialPointer.Pointer p = new DialPointer.Pointer();
		p.setFillPaint(Color.yellow);
		plot.addPointer(p);

		logger.debug("OUT");
		JFreeChart chart=new JFreeChart(name, plot);

		TextTitle title = setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}

		chart.setBackgroundPaint(color);
		return chart;
	}
 
Example 11
Source File: Thermometer.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a chart of type thermometer.
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart thermometer.
 */


public JFreeChart createChart(DatasetMap datasets) {
	logger.debug("IN");
	Dataset dataset=(Dataset)datasets.getDatasets().get("1");

	ThermometerPlot plot = new ThermometerPlot((ValueDataset)dataset);
	JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT,	plot, true);               
	chart.setBackgroundPaint(color);

	TextTitle title = setStyleTitle(name, styleTitle);
	chart.setTitle(title);
	if(subName!= null && !subName.equals("")){
		TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
		chart.addSubtitle(subTitle);
	}

	
	plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	plot.setPadding(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
	plot.setThermometerStroke(new BasicStroke(2.0f));
	plot.setThermometerPaint(Color.lightGray);
	plot.setGap(3);
	plot.setValueLocation(3);
	plot.setValuePaint(labelsValueStyle.getColor());
	plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

	plot.setRange(lower, upper);


	if(units.equalsIgnoreCase(FAHRENHEIT))plot.setUnits(ThermometerPlot.UNITS_FAHRENHEIT);	
	else if(units.equalsIgnoreCase(CELCIUS)) plot.setUnits(ThermometerPlot.UNITS_CELCIUS);	
	else if(units.equalsIgnoreCase(KELVIN)) plot.setUnits(ThermometerPlot.UNITS_KELVIN);	
	else plot.setUnits(ThermometerPlot.UNITS_NONE);


	// set subranges	
	for (Iterator iterator = intervals.iterator(); iterator.hasNext();){
		KpiInterval subrange = (KpiInterval) iterator.next();
		int range=0;
		if(subrange.getLabel().equalsIgnoreCase(NORMAL))range=(ThermometerPlot.NORMAL);
		else if(subrange.getLabel().equalsIgnoreCase(WARNING))range=(ThermometerPlot.WARNING);
		else if(subrange.getLabel().equalsIgnoreCase(CRITICAL))range=(ThermometerPlot.CRITICAL);

		plot.setSubrange(range, subrange.getMin(), subrange.getMax());
		if(subrange.getColor()!=null){
			plot.setSubrangePaint(range, subrange.getColor());
		}
		//plot.setDisplayRange(subrange.getRange(), subrange.getLower(), subrange.getUpper());	
	}
	//plot.setFollowDataInSubranges(true);
	logger.debug("OUT");

	return chart;       
}
 
Example 12
Source File: Meter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates the chart .
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart .
 */

public JFreeChart createChart(DatasetMap datasets) {

	Dataset dataset=(Dataset)datasets.getDatasets().get("1");

	MeterPlot plot = new MeterPlot((ValueDataset)dataset);
	plot.setRange(new Range(lower, upper));


	for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
		KpiInterval interval = (KpiInterval) iterator.next();

		plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()), 
				Color.lightGray, new BasicStroke(2.0f), 
				interval.getColor()));
	}

	plot.setNeedlePaint(Color.darkGray);
	plot.setDialBackgroundPaint(Color.white);
	plot.setDialOutlinePaint(Color.gray);
	plot.setDialShape(DialShape.CHORD);
	plot.setMeterAngle(260);
	plot.setTickLabelsVisible(true);
	//set tick label style
	Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
	plot.setTickLabelFont(tickLabelsFont);
	plot.setTickLabelPaint(labelsTickStyle.getColor());
	plot.setTickSize(5.0);
	plot.setTickPaint(Color.lightGray);
	if(units!=null){
		plot.setUnits(units);
	}

	plot.setValuePaint(labelsValueStyle.getColor());
	plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

	JFreeChart chart = new JFreeChart(name, 
			JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
	chart.setBackgroundPaint(color);
	
	TextTitle title = setStyleTitle(name, styleTitle);
	chart.setTitle(title);
	if(subName!= null && !subName.equals("")){
		TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
		chart.addSubtitle(subTitle);
	}

	return chart;
}
 
Example 13
Source File: LineChart.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(){
	
	logger.debug("IN");
	CategoryPlot plot = new CategoryPlot();

	
	NumberAxis rangeAxis = new NumberAxis("Kpi Values");
	rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12 ));
	Color colorLabel= Color.decode("#000000");
	rangeAxis.setLabelPaint(colorLabel);
	rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
	rangeAxis.setTickLabelPaint(colorLabel);
	plot.setRangeAxis(rangeAxis);
	
	CategoryAxis domainAxis = new CategoryAxis();
	domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setLabelPaint(colorLabel);
       domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setTickLabelPaint(colorLabel);
	plot.setDomainAxis(domainAxis);

	plot.setOrientation(PlotOrientation.VERTICAL);
	plot.setRangeGridlinesVisible(true);
	plot.setDomainGridlinesVisible(true);


	//I create a line renderer 
	MyStandardCategoryItemLabelGenerator generator=null;

		LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
		lineRenderer.setShapesFilled(true);
		lineRenderer.setBaseItemLabelGenerator(generator);
		lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12 ));
		lineRenderer.setBaseItemLabelPaint(colorLabel);
		lineRenderer.setBaseItemLabelsVisible(true);

		DefaultCategoryDataset datasetLine=(DefaultCategoryDataset)datasetMap.getDatasets().get("line");

			for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
				String serName = (String) iterator.next();
				String labelName = "";
				int index=-1;
				index=datasetLine.getRowIndex(serName);
				
				Color color=Color.decode("#990200");
				lineRenderer.setSeriesPaint(index, color);	
			}

		plot.setDataset(0,datasetLine);
		plot.setRenderer(0,lineRenderer);

	plot.getDomainAxis().setCategoryLabelPositions(
			CategoryLabelPositions.UP_45);
	JFreeChart chart = new JFreeChart(plot);
	logger.debug("Chart created");
	TextTitle title=new TextTitle(name,new Font("Arial", Font.BOLD, 16 ),Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.setTitle(title);
	TextTitle subTitle =new TextTitle(subName,new Font("Arial", Font.PLAIN, 12 ),Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle);
	TextTitle subTitle2 =new TextTitle(subName,new Font("Arial", Font.PLAIN, 8 ),Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle2);
	chart.removeLegend();
	
	chart.setBackgroundPaint(Color.white);
	logger.debug("OUT");
	return chart;
}
 
Example 14
Source File: SimpleScatter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(DatasetMap datasets) {

		DefaultXYDataset dataset=(DefaultXYDataset)datasets.getDatasets().get("1");

		JFreeChart chart = ChartFactory.createScatterPlot(
				name, yLabel, xLabel, dataset, 
				PlotOrientation.HORIZONTAL, false, true, false);

		Font font = new Font("Tahoma", Font.BOLD, titleDimension);
		//TextTitle title = new TextTitle(name, font);
		TextTitle title =setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		chart.setBackgroundPaint(Color.white);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}
		
		XYPlot plot = (XYPlot) chart.getPlot();
		plot.setForegroundAlpha(0.65f);

		XYItemRenderer renderer = plot.getRenderer();


		int seriesN=dataset.getSeriesCount();
		if(colorMap!=null){
			for (int i = 0; i < seriesN; i++) {
				String serieName=(String)dataset.getSeriesKey(i);
				Color color=(Color)colorMap.get(serieName);
				if(color!=null){
					renderer.setSeriesPaint(i, color);
				}	
			}
		}

		// increase the margins to account for the fact that the auto-range 
		// doesn't take into account the bubble size...
		NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
		domainAxis.setAutoRange(true);
		domainAxis.setRange(yMin, yMax);
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setAutoRange(true);
		rangeAxis.setRange(xMin,xMax);
		
		if(legend==true){
			drawLegend(chart);
		}
		return chart;
	}
 
Example 15
Source File: AdminJFreeChartController.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
private String createXYLineChart(HttpSession session, String title,
		String xtitle, String ytitle, int width, int height, String useMap,
		PrintWriter pw) {
	XYDataset xydataset = getXYDataset();
	String filename = "";

	JFreeChart chart = ChartFactory.createXYLineChart(title, xtitle,
			ytitle, xydataset, PlotOrientation.VERTICAL, true, true, true);
	chart.setTitle(new TextTitle(title, new Font("Calibri",
			Font.ITALIC, 12)));
	chart.getTitle().setFont(new Font("Calibri", Font.PLAIN, 12));
	chart.setBackgroundPaint(Color.white);

	/*
	 
	final XYPlot xyplot = (XYPlot) jfreechart.getPlot();
	xyplot.setBackgroundPaint(Color.lightGray);
	xyplot.setDomainGridlinePaint(Color.white);
	xyplot.setDomainGridlinesVisible(true);
	xyplot.setRangeGridlinePaint(Color.white);
	xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

	final ValueAxis categoryAxis = xyplot.getDomainAxis();
	// categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
	categoryAxis.setLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	categoryAxis.setTickLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));

	NumberAxis numberAxis = (NumberAxis) xyplot.getRangeAxis();
	numberAxis.setLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	numberAxis.setTickLabelFont(new Font("Calibri", Font.TYPE1_FONT, 12));
	numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
	numberAxis.setAutoRangeIncludesZero(true);

	XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot
			.getRenderer();
	xylineandshaperenderer.setShapesVisible(true);
	xylineandshaperenderer.setShapesFilled(true);

	xylineandshaperenderer.setSeriesLinesVisible(0, false);
	xylineandshaperenderer.setSeriesShapesVisible(1, false);
	xyplot.setRenderer(xylineandshaperenderer);

	xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 10F, 6F }, 0.0F));
	xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 6F, 6F }, 0.0F));
	xylineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1,
			1.0F, new float[] { 2.0F, 6F }, 0.0F));

	xylineandshaperenderer
			.setBaseItemLabelGenerator(new IntervalXYItemLabelGenerator(
					"({1},{2})", NumberFormat.getNumberInstance(),
					NumberFormat.getNumberInstance()));
	xylineandshaperenderer.setURLGenerator(new StandardXYURLGenerator(
			"/hrms/admin_charts", "seriesName", "itemName"));

	xylineandshaperenderer.setLegendTextFont(0, new Font("Calibri",
			Font.TYPE1_FONT, 12));
	xylineandshaperenderer.setLegendTextFont(1, new Font("Calibri",
			Font.TYPE1_FONT, 12));
	xylineandshaperenderer.setLegendTextFont(2, new Font("Calibri",
			Font.TYPE1_FONT, 12));
        */
	
      
      final XYPlot plot = chart.getXYPlot( );
      XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer( );
      renderer.setSeriesPaint( 0 , Color.RED );
      renderer.setSeriesPaint( 1 , Color.GREEN );
      renderer.setSeriesPaint( 2 , Color.YELLOW );
      renderer.setSeriesStroke( 0 , new BasicStroke( 4.0f ) );
      renderer.setSeriesStroke( 1 , new BasicStroke( 3.0f ) );
      renderer.setSeriesStroke( 2 , new BasicStroke( 2.0f ) );
      plot.setRenderer( renderer );
	ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

	try {
		filename = ServletUtilities.saveChartAsPNG(chart, width,
				height, info, session);
		ChartUtilities.writeImageMap(pw, useMap, info, false);
		pw.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return filename;
}
 
Example 16
Source File: PanamaHitek_DualDialChart.java    From PanamaHitek_Arduino with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void buildChart() {

            dataset1 = new DefaultValueDataset(0);
            dataset2 = new DefaultValueDataset(0);
            DialPlot dialplot = new DialPlot();
            dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
            dialplot.setDataset(0, dataset1);
            dialplot.setDataset(1, dataset2);
            StandardDialFrame standarddialframe = new StandardDialFrame();
            standarddialframe.setBackgroundPaint(Color.lightGray);
            standarddialframe.setForegroundPaint(Color.darkGray);
            dialplot.setDialFrame(standarddialframe);
            GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220));
            DialBackground dialbackground = new DialBackground(gradientpaint);
            dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
            dialplot.setBackground(dialbackground);
            DialTextAnnotation dialtextannotation = new DialTextAnnotation(variableName);
            dialtextannotation.setFont(new Font("Dialog", 1, 12));
            dialtextannotation.setRadius(0.7D);
            dialplot.addLayer(dialtextannotation);
            DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
            dialvalueindicator.setFont(new Font("Dialog", 0, 10));
            dialvalueindicator.setOutlinePaint(Color.darkGray);
            dialvalueindicator.setRadius(0.6D);
            dialvalueindicator.setAngle(-103D);
            dialplot.addLayer(dialvalueindicator);
            DialValueIndicator dialvalueindicator1 = new DialValueIndicator(1);
            dialvalueindicator1.setFont(new Font("Dialog", 0, 10));
            dialvalueindicator1.setOutlinePaint(Color.red);
            dialvalueindicator1.setRadius(0.6D);
            dialvalueindicator1.setAngle(-77D);
            dialplot.addLayer(dialvalueindicator1);
            StandardDialScale standarddialscale = new StandardDialScale(chartOuterBottonLimit, chartOuterTopLimit, -120D, -300D, outerMajorDivisions, outerMinorDivisions);
            standarddialscale.setTickRadius(0.88D);
            standarddialscale.setTickLabelOffset(0.15D);
            standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
            dialplot.addScale(0, standarddialscale);
            StandardDialScale standarddialscale1 = new StandardDialScale(chartInnerBottonLimit, chartInnerTopLimit, -120D, -300D, innerMajorDivisions, innerMinorDivisions);
            standarddialscale1.setTickRadius(0.5D);
            standarddialscale1.setTickLabelOffset(0.15D);
            standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 12));
            standarddialscale1.setMajorTickPaint(Color.red);
            standarddialscale1.setMinorTickPaint(Color.red);
            dialplot.addScale(1, standarddialscale1);
            dialplot.mapDatasetToScale(1, 1);
            StandardDialRange standarddialrange = new StandardDialRange(90D, 100D, Color.blue);
            standarddialrange.setScaleIndex(1);
            standarddialrange.setInnerRadius(0.6D);
            standarddialrange.setOuterRadius(0.6D);
            dialplot.addLayer(standarddialrange);
            org.jfree.chart.plot.dial.DialPointer.Pin pin = new org.jfree.chart.plot.dial.DialPointer.Pin(1);
            pin.setRadius(0.55D);
            dialplot.addPointer(pin);
            org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(0);
            dialplot.addPointer(pointer);
            DialCap dialcap = new DialCap();
            dialcap.setRadius(0.1D);
            dialplot.setCap(dialcap);
            JFreeChart jfreechart = new JFreeChart(dialplot);
            jfreechart.setTitle(chartTitle);
            add(new ChartPanel(jfreechart));
        }