Profiling SegmentedTimeline

Discussion about JFreeChart related to stockmarket charts.
Posts: 10
Joined: Mon Feb 16, 2009 6:39 pm

Profiling SegmentedTimeline

Post by Celso » Mon Feb 16, 2009 6:56 pm

Hi folks,

i created a candlestick chart and i use SegmentedTimeline, but my dataset has a lot of information (about 2500 bars).

I am using NetBeans Profiler to view the performace of my application, and i saw a big problem with SegmentedTimeline, it consumes about 50MB!!!

Problem has encountered at SegmentedTimeline#getSegment(long), it creates new object all the time.

How can I remove days from TickUnit when I don´t have value at dataset, without using SegmentedTimeline?


ps.: sorry about my english, I hope you can understand it!

Posts: 2
Joined: Mon Jul 20, 2009 6:27 am

Re: Profiling SegmentedTimeline

Post by promagma » Mon Jul 20, 2009 6:58 am

SegmentedTimeline is very slow .... I wanted to post my experiences, hopefully it can help someone. It causes things to run something like 10 or 20 times slower. I have a dynamic plot, so speed is critical. I tried the "FAST" classes for dynamic updates. Optimized to the bone .... it was faster, but still too slow.

So I came up with another approach, which works beautifully. I don't use SegmentedTimeline or DateAxis at all. I use a NumberAxis, and an overrided NumberFormat class "IndexFormat". It has my own code holding an irregular timeline, so it can take an ordinary x-value and return the date/time label that I want. The overrided NumberFormat is applied to appear on the Axis and the Tooltip.

Here is some code ..... it won't compile but is good for the idea

Code: Select all

IndexFormat chartFormat = new IndexFormat();

priceSet = new dynamicOHLCDataset();
NumberAxis timeAxis = new NumberAxis("");
NumberAxis valueAxis = new NumberAxis("");
HighLowRenderer renderer = new HighLowRenderer();
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("({1}, {2})", chartFormat, (new DecimalFormat("##0.00"))));
XYPlot thisPlot = new XYPlot(priceSet, timeAxis, valueAxis, renderer);
chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thisPlot, false);

TickUnits chartTickUnits = new TickUnits();
chartTickUnits.add(new NumberTickUnit(30, chartFormat));

XAxis = (NumberAxis)thisPlot.getDomainAxis();
XAxis.setTickLabelFont(new Font("Arial", Font.BOLD, 8));

private class IndexFormat extends NumberFormat
	public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition)
		// Here I use "number" to index into my own implementation of an irregular timeline,
        // and return a formatted date/time
	// These are never used, but a dummy implementation is required
	public void applyLocalizedPattern(String pattern) { }
	public void applyPattern(String pattern) { }
	public Number parse(String text, ParsePosition pos) { return 0.0f; }
	public StringBuffer format(long number, StringBuffer result, FieldPosition fieldPosition) { return new StringBuffer(""); }
	public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(""); }

Posts: 2
Joined: Sun Sep 06, 2009 1:42 pm
antibot: No, of course not.

Re: Profiling SegmentedTimeline

Post by ssingh » Sun Sep 06, 2009 2:09 pm


I tried to use the NumberAxis in place of DateAxis but still it shows the weekend spaces. Am I missing something ?
Can you please add a demo code to help. This is what I do :

Code: Select all

 final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis);
      MyNumberFormat chartFormat = new MyNumberFormat();
      TickUnits chartTickUnits = new TickUnits();
      chartTickUnits.add(new NumberTickUnit(30, chartFormat));