Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-28-2009, 11:28 PM
Member
 
Join Date: Jun 2008
Posts: 76
Rep Power: 0
Ms.Ranjan is on a distinguished road
Default Help in using net.sourceforge.chart2d
Hi all

I am trying to use this package in my application to draw graphs.I am specifically interested in the "Vertical Bar Chart With Stack".you can find it in the link below

Chart2D: Vertical Bar Chart With Stack : Bar Chart Vertical*«*Chart*«*Java


Below is the code that i am working on..i am getting an arraylist of labelsAxisLabels[] from my application which changes dynamically.My problem is when the labelsAxisLabels[] is less than 22, the labels(Y-AXIS labels)are displayed in the graph .When the number of labels is increased(for eg:100 labels) the labels are not being displayed in the graph.The graph is shrinking its size.

I have tried to explain the problem as much as I can,I am sorry if its not clear.
But I hope someone might have used this package to draw graphs,any suggestion on how to appraoch the problem will be very much appreciated

Code:
public class FirstPanel extends JFrame implements ActionListener{
	class Measure extends JPanel
	{
		ArrayList<String> edgearry =new ArrayList<String>();
                         ArrayList<String> datavaluelist =new ArrayList<String>();
                     
                        //edgearry.add("data1");
                       //edgearry.add("data2");
                      //edgearry.add("data3");
                     //....
                     //.....
                     //edgearry.add("data100");
		
		condition con2=new condition();
		
		public Measure()
		{
		JComponent jcgraph=creategraphpanel();
            TitledBorder tgraph=new TitledBorder("Graph");
        	setBorder(tgraph);
            setLayout(new GridLayout(0,1));
            
            add(jcgraph);   
            
		}
		
		public JComponent creategraphpanel()
		{
			JPanel graphpanel=new JPanel();			graphpanel.add(getChart2DDemoE());
			JScrollPane scroller = new JScrollPane(graphpanel,					JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
					JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
			
			
			return scroller;
			
			
		}
private Chart2D getChart2DDemoE() {
 //<-- Begin Chart2D configuration -->

//edgearry is an arraylist of label(which i dynamically get from my application)			
  String labelsAxisLabels[]=(String[]) edgearry.toArray(new String[edgearry.size()]);
//Configure object properties
		    Object2DProperties object2DProps = new Object2DProperties();
		    object2DProps.setObjectTitleText ("Heading");

		    //Configure chart properties
		    Chart2DProperties chart2DProps = new Chart2DProperties();
		    chart2DProps.setChartDataLabelsPrecision (2);

		    //Configure legend properties
		    LegendProperties legendProps = new LegendProperties();
		    String[] legendLabels = {"label1", "label2", "label3","label4","label5"};
		    
		    legendProps.setLegendLabelsTexts (legendLabels);

		    //Configure graph chart properties
		    GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties();
		    
		    graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels);
		    graphChart2DProps.setLabelsAxisTitleText ("Heading");
		    graphChart2DProps.setNumbersAxisTitleText ("Heading");
		    graphChart2DProps.setChartDatasetCustomizeGreatestValue (true);
		    graphChart2DProps.setChartDatasetCustomGreatestValue (48f);
		    graphChart2DProps.setChartDatasetCustomizeLeastValue (true);
		    graphChart2DProps.setChartDatasetCustomLeastValue (0f);

		    //Configure graph properties
		    GraphProperties graphProps = new GraphProperties();
		    graphProps.setGraphAllowComponentAlignment (true);
		    graphProps.setGraphBarsRoundingRatio (0f);
		    graphProps.setGraphOutlineComponentsExistence (true);

		    //Configure dataset
		    Dataset dataset = new Dataset (5,edgearry.size(), 1);
		    int setcount=0;
                             datavaluelist.add("value1;value2;value3;");
                             datavaluelist.add("value1;");
                             datavaluelist.add("value2;value5");
                             datavaluelist.add("value3;value4");
                      
		    for(String al:datavaluelist)
			{
				String alarray[]=al.split(";");
				int firstCount=0;
				int secondCount=0;
				int thirdCount=0;
				int fourthCount=0;
				int fifthCount=0;
				
				for(int count=0;count<alarray.length;count++)
				{
				 if(alarray[count].equalsIgnoreCase("value1"))
					{
						firstCount++;
					}
				 else if(alarray[count].equalsIgnoreCase("value2"))
				 {
					 secondCount++; 
				 }
				 else if(alarray[count].equalsIgnoreCase("value3"))
				 {
					 thirdCount++; 
				 }
				 else if(alarray[count].equalsIgnoreCase("value4"))
				 {
					 fourthCount++; 
				 }
				 else if(alarray[count].equalsIgnoreCase("value5"))
				 {
					 fifthCount++; 
				 }
				
				}
	   dataset.set(0,setcount,0,firstCount*1f);
				   				   dataset.set(1,setcount,0,secondCount*1f);
				  				   dataset.set(2,setcount,0,thirdCount*1f);
				  				   dataset.set(3,setcount,0,fourthCount*1f);
				 				   dataset.set(4,setcount,0,fifthCount*1f);
				   				 setcount++;
				
			}
		    dataset.doConvertToStacked();
		    
		    //Configure graph component colors
		    MultiColorsProperties multiColorsProps = new MultiColorsProperties();

		    //Configure chart
		    LLChart2D chart2D = new LLChart2D();
		    chart2D.setObject2DProperties (object2DProps);
		    chart2D.setChart2DProperties (chart2DProps);
		    chart2D.setLegendProperties (legendProps);
		    chart2D.setGraphChart2DProperties (graphChart2DProps);
		    chart2D.addGraphProperties (graphProps);
		    chart2D.addDataset (dataset);
		    chart2D.addMultiColorsProperties (multiColorsProps);

		    //Optional validation:  Prints debug messages if invalid only.
		    if (!chart2D.validate (false)) chart2D.validate (true);

		    //<-- End Chart2D configuration -->

		    return chart2D;
		  }
public void actionPerformed(ActionEvent e) {
		Measure ass=new Measure();
		 JFrame frame = new JFrame("Graph Heading");
		 frame.getContentPane().add(ass);
		 frame.pack();
		 frame.setVisible(true); 
			
	}
			}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sourceforge.net down? angryboy Forum Lobby 0 06-07-2009 12:20 AM
how to connet to MS SQL in java by using net.sourceforge.jtds.jdbc driver cambo Database 0 12-18-2007 07:07 PM


All times are GMT +2. The time now is 12:48 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org