Suitable chart time for call-stack with duration information

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Posts: 1
Joined: Wed Oct 18, 2017 7:29 am
antibot: No, of course not.

Suitable chart time for call-stack with duration information

Post by mzampare » Wed Oct 18, 2017 10:54 am

Hi folks,

I am new to JFreeChart.
I need to create a plot which shows a call-stack functional decomposition which includes start time and end time in seconds (I guess in software development this is what some profiling tools do). It should show a hierachical call stack and may include repetition or parallel execution.

Consider the example:
F1 started at: 44 duration: 3245
F11 started at: 353 duration: 1258
F111 started at: 657 duration: 538
F12 started at: 1812 duration: 512
F12 started at: 2525 duration: 513
F13 started at: 3445 duration: 514
F13 started at: 3445 duration: 517

From the above data, F1 calls F11 which calls F111. The line of F1 will be wider (as calling function ) than all the others. F12 is called twice,sequentially, while F13 is called twice in parallel, the corresponding lines will be overlapping.

In theory this is almost like a GANTT chart, only that I see to be having problems with the creation of the SimpleTimePeriod:

Code: Select all

t = new Task(ee.getActivity().getName(), 
			new SimpleTimePeriod(date(1,Calendar.APRIL,2001), 
			   		     date(1,Calendar.MAY,2002) ) );
		t = new Task(ee.getActivity().getName(),
			new SimpleTimePeriod(ee.getStartTime(), ee.getEndTime() ));

The first (dummy) assignment above works (producing of course unrealistic bars with the same length, the second one doesn't (no chart displayed), probably the SimpleTimePeriod is not made to cope with seconds within one day.

Am I doing something wrong? And more in general, which is the best chart for my purposes, among those provided by JFreeChart ?
(I had considered going for the BarCharts but the bars in there all seem to start at the same level, which is zero, and that is different from what I need).

thanks in advance,


Posts: 1633
Joined: Sat Feb 17, 2007 1:51 pm

Re: Suitable chart time for call-stack with duration informa

Post by paradoxoff » Thu Oct 19, 2017 11:55 am

I may have misunderstood your problem, but I think that a CategoryPlot might be the wrong plot type, since it gives you little control about the exact positioning of the bars.
Try this example, that is using an XYPlot with an XYBarRenderer, and see whether it is what you need:

Code: Select all

import java.awt.Font;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBarRenderer;

public class HierarchicalXYBars{

    public static void main(final String[] args) {
        JFrame frame = new JFrame("Hierarchical XY Bars");    
        XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection();
        XYIntervalSeries s = new XYIntervalSeries("F1");
        s.add(44, 44, 3245+44, 1, 0.8, 1.2);
        s = new XYIntervalSeries("F11");
        s.add(353, 353, 353+1258, 2, 1.9, 2.1);
        s = new XYIntervalSeries("F111");
        s.add(657, 657, 657+538, 3, 2.95, 3.05);
        s = new XYIntervalSeries("F12");
        s.add(1812, 1812, 1812+512, 2, 1.9, 2.1);
        s.add(2525, 2525, 2525+512, 2, 1.9, 2.1);
        s = new XYIntervalSeries("F13");
        s.add(3445, 3445, 3445+514, 2, 1.75, 1.95);
        s.add(3445, 3445, 3445+517, 2, 2.05, 2.25);
        XYBarRenderer renderer = new XYBarRenderer();
        NumberAxis levelAxis = new NumberAxis("Level");
        levelAxis.setLabelFont(new Font("Arial",1,16));
        levelAxis.setTickLabelFont(new Font("Arial",1,12));
        NumberAxis timeAxis = new NumberAxis();
        timeAxis.setLabelFont(new Font("Arial",1,16));
        timeAxis.setTickLabelFont(new Font("Arial",1,12));
        XYPlot plot = new XYPlot(dataset, timeAxis, levelAxis, renderer);
        JFreeChart chart = new JFreeChart(plot);
        frame.getContentPane().add(new ChartPanel(chart));



Post Reply