Cookbook StackedBarChartGenerator

Hi

I am using JIRA 5.x development cookbook. I am trying to build Stacked barchart and page is erroring out and code also has lot of deprecated methods. Can you please let me know the issue. (Note: I could get the PIE chart to show up)

 

package com.multireport.charts;

import java.util.HashMap;
import java.util.Map;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import com.atlassian.jira.charts.Chart;
import com.atlassian.jira.charts.jfreechart.ChartHelper;
import com.atlassian.jira.charts.jfreechart.PieChartGenerator;
import com.atlassian.jira.charts.jfreechart.StackedBarChartGenerator;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.web.bean.I18nBean;
public class ChartGenerator {
	public Chart generateChart(JiraAuthenticationContext authenticationContext, int width, int height) {
		try {
			final Map<String, Object> params = new HashMap<String, Object>();
			// Create Dataset
			//==============  PIE chart =====================================
			/*
			DefaultPieDataset dataset = new DefaultPieDataset();
			dataset.setValue("One", 10L);
			dataset.setValue("Two", 15L);
			final ChartHelper helper = new PieChartGenerator(dataset, authenticationContext.getI18nHelper())
					.generateChart();
			helper.generate(width, height);
			params.put("chart", helper.getLocation());
			params.put("chartDataset", dataset);
			params.put("imagemap", helper.getImageMap());
			params.put("imagemapName", helper.getImageMapName());
			params.put("width", width);
			params.put("height", height);
			*/
			//====================================================================
			  
		      final ChartHelper helper = new StackedBarChartGenerator(createDataset(), "y-label", (I18nBean) authenticationContext.getI18nBean()).generateChart();
				helper.generate(width, height);
				params.put("chart", helper.getLocation());
				params.put("chartDataset", createDataset());
				params.put("imagemap", helper.getImageMap());
				params.put("imagemapName", helper.getImageMapName());
				params.put("width", width);
				params.put("height", height);
				
			return new Chart(helper.getLocation(), helper.getImageMap(), helper.getImageMapName(), params);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("Error generating chart", e);
		}
	}
	
	private static CategoryDataset createDataset() {
		        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		        dataset.addValue(7445, "JFreeSVG", "Warm-up");
		        dataset.addValue(24448, "Batik", "Warm-up");
		        dataset.addValue(4297, "JFreeSVG", "Test");
		        dataset.addValue(21022, "Batik", "Test");
		        return dataset;
		    }
}

Thanks

Abe

2 answers

1 accepted

I18nBean i18nBean = new I18nBean(jiraAuthenticationContext.getI18nHelper());

with

Constructor dependency injection for your report component

public class StackedReport extends AbstractReport {
    private final JiraAuthenticationContext jiraAuthenticationContext;
    public StackedReport(JiraAuthenticationContext jiraAuthenticationContext) {
        this.jiraAuthenticationContext = jiraAuthenticationContext;
    }

Tried I18nBean as follows - still no luck

public I18nBean geti18nBean() {
return new I18nBean(authenticationContext.getLoggedInUser());
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

90 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you