getRangeAxis() returns null..

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

getRangeAxis() returns null..

Post by lifeline2 » Mon Nov 09, 2009 8:56 am

Hi guys!!

I am creating a chart using below constructor after creating a CombinedDomainXYPlot object :
code for comboplot :

Code: Select all

 NumberAxis xAxis = new NumberAxis(PLOT_COMMON_X_AXIS_NAME);
  CombinedDomainXYPlot combPlot =new CombinedDomainXYPlot(xAxis);
I am adding a lot more XYPlot objects into the comboPlot object.
chart constructor :

Code: Select all

 chart = new JFreeChart(CHART_NAME, JFreeChart.DEFAULT_TITLE_FONT, combPlot, true);
  combPlot.setOrientation(PlotOrientation.VERTICAL);
System.out.println("Range Axis "+chart.getXYPlot().getRangeAxis());
It's printing Range Axis null

Any idea on this? as I am using it in my code. Lemme know if the info. is in-sufficient.


Thanks in advance...
Last edited by lifeline2 on Tue Dec 01, 2009 3:24 pm, edited 2 times in total.

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by lifeline2 » Tue Nov 10, 2009 6:26 am

Guys!

I found the problem as I was trying to get the range axis of combined plot rather then each XYPlot!

One more problem m facing is registering key Listener with my customised ChartPanel.
I search around the blog amazingly the simple problem looks tough!!
Any thing to do with focus ?
One more thing in CombinedDomainXYPlot there is a method getSubplots() but there is no such method to get a subplot by index or something like that! I am clue-less to handle events for each XYPlot/subplot :oops:

Hope there should be such method or workaround to achieve it isn't it?

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by lifeline2 » Tue Nov 10, 2009 8:03 am

lifeline2 wrote:One more problem m facing is registering key Listener with my customised ChartPanel.
I search around the blog amazingly the simple problem looks tough!!
Any thing to do with focus ?
I could listen to my key events now for ChartPanel.
lifeline2 wrote:One more thing in CombinedDomainXYPlot there is a method getSubplots() but there is no such method to get a subplot by index or something like that! I am clue-less to handle events for each XYPlot/subplot :oops:
But still struggling to get the XYPlot reference of CombinedDomainXYPlot where I am pressing the key ..

So far:

Code: Select all

XYPlot xyPlot =(XYPlot)((CombinedDomainXYPlot)chartPanel.getChart().getPlot()).getSubplots().get(0);

gives me the sub plot reference but how can I dynamically know the subplot index upon which I am pressing the key or clicking mouse or I have to register listeners for each subplot?

Please have an update on this... :cry:

TomHart
Posts: 7
Joined: Tue Sep 29, 2009 2:57 pm
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by TomHart » Thu Nov 12, 2009 11:31 pm

When a mouse event is generated, get the point at which the event is generated using the mouse event reference.

event.getPoint();

This call returns you a point in Java 2D co-ordinates.... So you need to convert this point to chart co-ordinates using the following method call:

valueToJava2D() or translateScreenToJava2D(point);

This call returns you a point in chart co-ordinates.... use this point to get the subplot index using the following method call....

plotInfo.getSubplotIndex(point);

plotInfo is PlotRenderingInfo that needs to be retrieved from ChartRenderingInfo.

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by lifeline2 » Fri Nov 20, 2009 8:18 am

Hi TomHart!!
Thanks for the support...

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by lifeline2 » Mon Nov 23, 2009 3:47 pm

Is it possible to zoom Only one subplot of a CombinedDomainXYPlot . I could able to zoom along range Axis But can I make it for domain-axis also. I tried with overriding zoomInDomain() method of my customized ChartPanel:

Code: Select all

public void zoomInDomain(double x, double y) {
Plot p = (XYPlot)(((CombinedDomainXYPlot)this.chart.getPlot()).getSubplots().get(this.getPlotIndex()));
if (p instanceof Zoomable) {
Zoomable plot = (Zoomable) p;
plot.zoomDomainAxes(
this.zoomInFactor, this.info.getPlotInfo(), 
translateScreenToJava2D(new Point((int) x, (int) y))
);
}
}


from the inputs so far I am getting selected sub Plot Index successfully instead all domain axes are getting zoomed or stretched .
Or is it not possible if I use a CombinedDomainXYPlot object? As I feel the Domain Axis is common to all sub plots(each sub plot is an XYPlot). Any idea 'll be highly appreciated ... :?:

Happy Coding.

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returning null

Post by lifeline2 » Mon Nov 23, 2009 4:07 pm

Just for the info . I am looking for it because I have 155 XYPlots in the CombinedDomainXYPlot and while zooming it takes lot of time even the zoom rectangle just sits there for several seconds...

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: getRangeAxis() returning null

Post by paradoxoff » Mon Nov 23, 2009 9:28 pm

All subplots of a CombinedDomainXYPlot use the same domain axis. if you zoom this axis, change the font, the line paint, ..., the range, it will affect all subplots.

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Zooming is very slow CombinedDomainXYPlot

Post by lifeline2 » Tue Dec 01, 2009 10:06 am

Please have a look into the demo(I derived from java2s.com as actually am running sim. stuff through bean shell script) . Do not know why zooming is slow . as the no. of plots increases zooming becomes slower and slower. and for 155 plots it just responds after a minute!!
can I make it faster. same response time for key and mouse listener also.

Code: Select all

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.*;
import org.jfree.data.general.SeriesException;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.plot.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.labels.*;
import org.jfree.chart.renderer.xy.*;


import java.awt.*;
import javax.swing.*;

public class TimeSeriesDemo5 extends ApplicationFrame {
    
    
    public TimeSeriesDemo5(final String title) {
    	 super(title);
    	 NumberAxis xAxis = new NumberAxis("PLOT_COMMON_X_AXIS_NAME");
    	  CombinedDomainXYPlot combPlot = new CombinedDomainXYPlot(xAxis);
    	  combPlot.setDataset(null);
    	  combPlot.setGap(5.0);
    	  combPlot.setBackgroundPaint(Color.lightGray);
    	  combPlot.setDomainGridlinePaint(Color.white);
    	  combPlot.setRangeGridlinePaint(Color.white);
    	  String[] POWClockFreqT = new String[] 
    	                                      { "OFF", "ON", "32K","2M","3_25M","6_5M","8_67M","13M","26M","27M","31_2M",
    	                                        "33_3M","39M","44_5M","48M","52M","78M","89M", "96M","104M","108M","124_8M",
    	                                        "133_25M", "138670K","156M", "178M","208M","312M","416M"
    	                                      };
    	  SymbolAxis yAxis0 = new SymbolAxis("PLOT_0_Y_AXIS_NAME",POWClockFreqT);
    	  TimeSeriesCollection dataCollection0 = new TimeSeriesCollection();
    	  dataCollection0.addSeries(createDataseries());
          XYToolTipGenerator toolTip  = new StandardXYToolTipGenerator();
          final int PLOT_STYLE = StandardXYItemRenderer.LINES;
          StandardXYItemRenderer renderer = new StandardXYItemRenderer( PLOT_STYLE);
          renderer.setBaseToolTipGenerator( toolTip );
          XYPlot  plot0 = new XYPlot(dataCollection0, xAxis, yAxis0, renderer);
          for (int i=1;i<21;i++)
          {
          combPlot.add(plot0,i); 
          }
       
       
        final JFreeChart  chart = new JFreeChart("CHART_NAME", JFreeChart.DEFAULT_TITLE_FONT, combPlot, true);
        combPlot.setOrientation(PlotOrientation.VERTICAL);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize( new Dimension( 1250, 300*20 ) );//10000
        JScrollPane scrollPane = new JScrollPane(chartPanel);
        chartPanel.setMouseZoomable(true, false);
        setContentPane(scrollPane);
        
    }
       
  
    private TimeSeries createDataseries() {
        
        final TimeSeries series = new TimeSeries("Random Data");
        Day current = new Day(1, 1, 1990);
        double value = 100.0;
        for (int i = 0; i < 100; i++) {
            try {
                value = value + Math.random() - 0.5;
                series.add(current, new Double(value));
                current = (Day) current.next();
            }
            catch (SeriesException e) {
                System.err.println("Error adding to series");
            }
        }
        return series;
    }
    
   
    public static void main(final String[] args) {

        final String title = "Title";
        final TimeSeriesDemo5 demo = new TimeSeriesDemo5(title);
        demo.pack();
        RefineryUtilities.positionFrameRandomly(demo);
        demo.setVisible(true);

    }

}

I overridden ChartPanel class for my need so scaling is not an issue and plot doesn't looks stretched.

One more info there are approx. 100*155(100 points per subplot) points in my entire CombinedDomainXYPlot. do not know is that is the reason ??? :?:

lifeline2
Posts: 11
Joined: Wed Oct 21, 2009 10:04 am
antibot: No, of course not.

Re: getRangeAxis() returns null..

Post by lifeline2 » Fri Dec 11, 2009 11:16 am

Issue is being resolved..!
http://forums.sun.com/thread.jspa?threa ... 0&tstart=0
Thanks...

Locked