Java Code Examples for org.jfree.chart.ChartUtilities#writeImageMap()

The following examples show how to use org.jfree.chart.ChartUtilities#writeImageMap() . 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: AbstractChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
public String getChartMap(String chartMapId) throws IOException {
    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);

    try {
        ChartUtilities.writeImageMap(pw, chartMapId, chartRenderingInfo, new StandardToolTipTagFragmentGenerator(),
            new StandardURLTagFragmentGenerator());
    } finally {
        IOUtils.closeQuietly(pw);
    }

    return writer.toString();
}
 
Example 2
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;
}