Page 1 of 1

Profiling SegmentedTimeline

Posted: Mon Feb 16, 2009 6:56 pm
by Celso
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?

Thanks,
Celso

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

Re: Profiling SegmentedTimeline

Posted: Mon Jul 20, 2009 6:58 am
by promagma
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));
XAxis.setStandardTickUnits(chartTickUnits);



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(""); }
}

Re: Profiling SegmentedTimeline

Posted: Sun Sep 06, 2009 2:09 pm
by ssingh
Hi,

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();
      dateAxis.setNumberFormatOverride(chartFormat);
      TickUnits chartTickUnits = new TickUnits();
      chartTickUnits.add(new NumberTickUnit(30, chartFormat));
      dateAxis.setStandardTickUnits(chartTickUnits);