Rym
Rym

Reputation: 77

How to develop a JIRA plugin that display charts?

I am a newbie in JIRA World, my mission is to develop a JIRA plugin that display charts (pies, histogram, etc.). The user would choose the criteria of search and the type of charts, and the user should be able to save those charts (Word/PDF).

I don't know if I should develop a report plugin and use JFreeChart for charting or develop a charting plugin (I haven't seen any example of charting plugin). I have done some research about report plugin and I haven't found an example show how to Use JFreechart!! also I haven't found any example show how to use jasperReport (or another tool) to generate word or PDF report.

The user should access to the plugin from a tab like interface (administration, home, etc.)

Example of KPI (key performance indicator) to display:

PS: I'm using JIRA 4.3.3

Upvotes: 4

Views: 6451

Answers (6)

Ferenc Kiss
Ferenc Kiss

Reputation: 307

The best alternative to save your time from plugin programming, yet giving you incredible features and flexibility, is generating the charts in Excel via exporting JIRA data with the Better Excel Plugin.

How does it work?

  1. You create a template XLSX file with special placeholder, tags for the actual data.
  2. Define so-called named ranges and generate (empty) charts from them, using all the charting features in Excel. (As MS Excel is still the most versatile and most widely used data visualization tool, it is almost guaranteed that your use case will be supported and you will find tons of help by Googling the web.)
  3. When you export this template, the add-on will fill the named range with your issues' data and the chart "wakes up"!

The end-result may look like this (in its own worksheet):

enter image description here

Upvotes: 0

eXistPierre
eXistPierre

Reputation: 1031

in velocity:

    #set($cht = $chart)
    #if ($cht)
    #if ($cht.imageMap)
    $cht.imageMap
    #end
    <p class="report-chart">
        <img src='$baseurl/charts?filename=$chart.location' border='0'
        #if ($cht.imageMap) usemap="\#$cht.imageMapName" #end/>
    </p>
    #end

webwork:

@SuppressWarnings("unused")
public Chart getChart() {
    JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();

     final int CHART_WIDTH = 300;
     final int CHART_HEIGHT = 300;

    try {
        final Map<String, Object> params = new HashMap<String, Object>();
        // Create Dataset
        DefaultPieDataset dataset = new DefaultPieDataset();

        dataset.setValue("One", 10L);
        dataset.setValue("Two", 15L);

        final I18nBean i18nBean = new I18nBean(authenticationContext.getUser().getDirectoryUser());

        final ChartHelper helper = new PieChartGenerator(dataset, i18nBean).generateChart();
        helper.generate(CHART_WIDTH, CHART_HEIGHT);

        params.put("chart", helper.getLocation());
        params.put("chartDataset", dataset);
        params.put("imagemap", helper.getImageMap());
        params.put("imagemapName", helper.getImageMapName());
        params.put("width", CHART_WIDTH);
        params.put("height", CHART_HEIGHT);

        Chart ch = new Chart(helper.getLocation(), helper.getImageMapHtml(), helper.getImageMapName(), params);
        return ch;

    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Error generating chart", e);
    }
}

result:

enter image description here

Upvotes: 1

Mladen B.
Mladen B.

Reputation: 2996

Try reading the article Creating a pie chart in JIRA from the great book "JIRA 5.x Development Cookbook" by Jobin Kuruvilla.

The most important thing is to populate your dataset, which will be used to generate the needed chart. Consider the example from that book, which shows the java side of that plugin:

public Chart generateChart(JiraAuthenticationContext authenticationContext, int width, int height) {
    try {
      final Map<String, Object> params = new HashMap<String, Object>();
      // Create Dataset
      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);

      return new Chart(helper.getLocation(), helper.getImageMap(), helper.getImageMapName(), params);

    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("Error generating chart", e);
    }
}

and the velocity template for such purpose:

#if ($chart)
    #if ($imagemap)
        $imagemap
    #end
    <p class="report-chart">
        <img src='$baseurl/charts?filename=$chart' border='0' #if ($imagemap) usemap="\#$imagemapName" #end/>
    </p>
#end

That's it in the most basic example. But also, take a look at the ChartFactory and ChartUtils interfaces, to get the deeper idea how to create various types of charts.

Upvotes: 2

Matt
Matt

Reputation: 442

There is a JIRA plugin to export charts to Word, which covers part of what you wanted to do. https://marketplace.atlassian.com/plugins/com.clariostechnology.officecharts.officecharts

Also see Intelligent Reporter which gives more options for formatting charts and allows you to use Word files as templates and fill in the charts and other data.

https://marketplace.atlassian.com/plugins/com.clariostechnology.intelligentreports

Upvotes: 2

Ferenc Kiss
Ferenc Kiss

Reputation: 307

See this tutorial about drawing various types of charts to visualize JIRA data: http://www.midori.hu/products/jira-pdf-view-plugin/documentation/charts

The technique explained there relies on capturing your custom KPI calculation logic in concise Groovy scripts, rendering the charts with the de-facto standard JFreeChart, all backed by our JIRA PDF View Plugin.

enter image description here

(Discl: the plugin mentioned there is our commercially supported software.)

Upvotes: -1

You don't need to write a plugin to do that-these are native capabilities in JIRA. If you're hellbent on writing a plugin I'd use JFreeChart. See the JIRA Charting Plugin and JQL filters to get your two listed KPIs.

Upvotes: 1

Related Questions