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

This widget could not be displayed.
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;
    }
This widget could not be displayed.

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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

178 views 1 3
Join discussion

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