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 Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,084 views 6 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot