How to have multiple domain axes in CombinedDomainXYPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
yji
Posts: 1
Joined: Wed Oct 08, 2008 6:47 pm

How to have multiple domain axes in CombinedDomainXYPlot

Post by yji » Wed Oct 08, 2008 6:53 pm

I'm recently doing sth. which needs multiple domain axes in a CombinedDomainXYPlot. It seems the regular way of adding axes using "setDomainAxis", "setDomainAxisLocation" doesn't work for this case.

Any suggestions? Thanks a lot.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Oct 09, 2008 8:08 am

The point of the CombinedDomainXYPlot is that all the subplots *share* the same domain axis. I'd be surprised if it were possible to get this working with multiple domain axes.

Can you show an example of what you are trying to display? Perhaps then I can suggest another approach.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

vijaypulluri
Posts: 2
Joined: Tue Feb 20, 2018 5:48 am
antibot: No, of course not.

Re: How to have multiple domain axes in CombinedDomainXYPlot

Post by vijaypulluri » Wed Apr 18, 2018 6:49 am

Hi David,

Can you Please help me with this Thread, even I am having this issue.
I am beginner to JfreeChart. I am using combinedDomainXYplot for displaying subplots within a single graph.
However my requirement is to have individual domain axis rather than all sharing the same domain axis. Kindly do the needful.

Orginal Graph.
Image
https://imgur.com/a/KrGIr

My Requirement
Image

https://imgur.com/a/LP0f6
My Code is as below.

Code: Select all

package com.lge;
import java.awt.Color; 
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart; 
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset; 
import org.jfree.ui.ApplicationFrame; 
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot; 
import org.jfree.chart.plot.PlotOrientation; 
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;

import java.text.SimpleDateFormat;

public class subPlotsquery extends ApplicationFrame {

	static String filepath;
	static String filenames;
	static String callindex;
   public subPlotsquery( String applicationTitle, String chartTitle ) {
      super(applicationTitle);
      
      JFreeChart xylineChart2 = createChart();   
      ChartPanel chartPanel = new ChartPanel( xylineChart2, true,true,false,true,true );
      chartPanel.setPreferredSize( new java.awt.Dimension( 800 , 600 ) );

      setContentPane( chartPanel );
      chartPanel.setMouseWheelEnabled(true);
      chartPanel.setDomainZoomable(true);
      //setSize(1024, 768);
      setSize(1500, 1000);
      
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLocationRelativeTo(null);
   }

   private JFreeChart createChart() {
	   
	   final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
	   
	   	final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
		renderer1.setSeriesPaint(0, Color.RED);
		final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
		renderer2.setSeriesPaint(0, Color.BLACK);
		final XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true, false);
		renderer3.setSeriesPaint(0, Color.MAGENTA);
    
	    
	    final XYLineAndShapeRenderer[] renderers = new XYLineAndShapeRenderer[]{renderer1,renderer2,renderer3};   
	    plot.setGap(10.0);
	    
	    plot.setOrientation(PlotOrientation.VERTICAL);
	    TimeSeries ser1 = new TimeSeries("Series 1");
	    TimeSeries ser2 = new TimeSeries("Series 2");
	    TimeSeries ser3 = new TimeSeries("Series 3");  
	    
	    final TimeSeries[] tsArray = new TimeSeries[]{ser1, ser2, ser3};
	     final String[] labels = new String[]{"Series 1", "Series 2", "Series 3"};

	    ser1.addOrUpdate(new Millisecond(189,10,10,4,1,1,2018),110);
	    ser1.addOrUpdate(new Millisecond(345,20,20,4,1,1,2018),220);
	    ser1.addOrUpdate(new Millisecond(542,25,30,4,1,1,2018),100);
	    ser1.addOrUpdate(new Millisecond(658,35,40,4,1,1,2018),75);
	    ser1.addOrUpdate(new Millisecond(983,55,50,4,1,1,2018),550);
	    
        ser2.addOrUpdate(new Millisecond(189,10,10,9,1,1,2018),-50);
        ser2.addOrUpdate(new Millisecond(345,20,20,9,1,1,2018),-40);
        ser2.addOrUpdate(new Millisecond(542,25,30,9,1,1,2018),-30);
        ser2.addOrUpdate(new Millisecond(658,35,40,9,1,1,2018),-40);
        ser2.addOrUpdate(new Millisecond(983,55,50,9,1,1,2018),-10);
        
        ser3.addOrUpdate(new Millisecond(189,10,10,12,1,1,2018),-110);
        ser3.addOrUpdate(new Millisecond(345,20,20,12,1,1,2018),-220);
        ser3.addOrUpdate(new Millisecond(542,25,30,12,1,1,2018),-30);
        ser3.addOrUpdate(new Millisecond(658,35,40,12,1,1,2018),40);
        ser3.addOrUpdate(new Millisecond(983,55,50,12,1,1,2018),-550);
				     
	
		  for (int i = 0; i < tsArray.length; i++) {
		        final XYDataset ts = new TimeSeriesCollection(tsArray[i]);
		        final XYPlot p = new XYPlot(ts, new DateAxis(labels[i]), new NumberAxis(labels[i]), renderers[i]);
		        DateAxis axis = (DateAxis) p.getDomainAxis();
		        axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss.SSS"));
		        axis.setVerticalTickLabels(true);
		        plot.add(p);
		      }
		  
//		  TimeSeriesCollection ser1dataset = new TimeSeriesCollection(ser1);
//		  TimeSeriesCollection ser2dataset = new TimeSeriesCollection(ser2);
//		  TimeSeriesCollection ser3dataset = new TimeSeriesCollection(ser3);
		  return new JFreeChart("Multiple Subplots Graph", JFreeChart.DEFAULT_TITLE_FONT, plot, true);	  
   }

   public static void main( String[ ] args ) {
	     
	   subPlotsquery chart = new subPlotsquery("Multiple Subplots Graph",
         "SUB Plots");
      
      //RefineryUtilities.centerFrameOnScreen( chart );          
      chart.setVisible( true ); 
   }
}

vijaypulluri
Posts: 2
Joined: Tue Feb 20, 2018 5:48 am
antibot: No, of course not.

Re: How to have multiple domain axes in CombinedDomainXYPlot

Post by vijaypulluri » Thu Apr 19, 2018 2:04 pm

Can Some one help me with my query,

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: How to have multiple domain axes in CombinedDomainXYPlot

Post by John Matthews » Sat Apr 21, 2018 6:39 pm

Can you add your individual plots to a JPanel having GridLayout(0, 1)? An example is cited here.

Locked