anila

XML Framing For Uncontinuous data in java!

Recommended Posts

Hi,

 i am not generating xml by using any parsers,apis.

I am just forming the data as xml nodes which has to pass to fussion charts.

 

From database i was getting data like this,which has below.

 

Year Month Series name Values    2008 7 CARDIAC 100    2008 7 DU- IT 100    2008 7 MULTIVENDOR 100    2008 8 CARDIAC 100    2008 8 DU- IT 67    2008 8 P-TECH 100    2008 9 CARDIAC 100    2008 9 DU- IT 67    2008 9 NETWORKING 0    2008 9 P-TECH 100    2008 10 CARDIAC 100    2008 10 DU- IT 100    2008 10 MULTIVENDOR 100    2008 10 NETWORKING 50    2008 10 P-TECH 100    2008 11 CARDIAC 100    2008 11 DU- IT 100    2008 11 MULTIVENDOR 100    2008 12 CARDIAC 67    2008 12 DU- IT 100    2008 12 MULTIVENDOR 50    2008 12 P-TECH 100    2009 3 CARDIAC 100    2009 3 DU- IT 100    2009 3 MULTIVENDOR 100    2009 3 NETWORKING -100    2009 3 P-TECH 100    2009 6 CARDIAC 50    2009 6 DU- IT 100    2009 6 MULTIVENDOR 100 

I am trying to plot msline chart using msline.swf file in jsp.

I am storing each column in one bean whch are coming from database.

After tat i m using prepareList(vB_CL_Cust_NPS.getYr4_data(),nps_mn1,vB_CL_Cust_NPS.getSegment4_data(),vB_CL_Cust_NPS.getNps4_data()) whch accepts 4 columns as beans from dtabase.

 

prepareList() cretas one list object with data whch are passed to that method.

After that i am using readData(List list),whch accepts above list as parameter.

 

public Vector readData(List list){   	Vector data = new Vector();   	LinkedHashMap mapOfCategory = new LinkedHashMap();   	List alRegionMonthValueList = new ArrayList();   	Map mapOfBar = new HashMap();   	Map mapOfDataSet = new HashMap();   	for (int i =0; i< list.size(); i++){   							Yr2_Mn2_Region_code2_Nps2 obj = (Yr2_Mn2_Region_code2_Nps2)list.get(i);   		String categoryLabel = obj.getMn2() + "-" + obj.getYr2();   		mapOfCategory.put(categoryLabel, new Category(categoryLabel) );    								String regionKey = obj.getRegion_code2();   				  DataSet objDataSet = new DataSet(regionKey );   						   			if (mapOfDataSet.containsKey(regionKey )){   				//System.out.println("*Yes" );   				DataSet objDataSetAlreadyAdded = (DataSet)mapOfDataSet.get(regionKey);   				List setListAlreadyAdded = objDataSetAlreadyAdded.getListOfSet();   				setListAlreadyAdded.add(obj.getNps2());   																 objDataSet.setListOfSet(setListAlreadyAdded);   																 mapOfDataSet.put(regionKey,objDataSetAlreadyAdded);   								   			}else{   				List setList = new ArrayList();   				setList.add (obj.getNps2() );   				objDataSet.setListOfSet(setList);   				mapOfDataSet.put( regionKey,objDataSet);    				//System.out.println("*else" );   			}     										data.add( 0, [color=red]mapOfCategory[/color]);   				data.add( 1, [color=red]mapOfDataSet[/color]);    return data;   }  

public String prepareCategoriesXML(LinkedHashMap mapOfCategory){   StringBuffer buffer = new StringBuffer();   buffer.append("");     Set s=mapOfCategory.keySet();   Iterator it=s.iterator();   while(it.hasNext()) {   String me =""+it.next();     Category objCategory =(Category)mapOfCategory.get(me);   buffer.append("<category label='"+objCategory.getLabel()+"'/>");   System.out.println("Categeroies"+objCategory.getLabel());}   return buffer.toString();   }   public String prepareDatasetXML(Map mapOfDataSet){   		StringBuffer buffer1 = new StringBuffer();   		buffer1.append("");     		Set s=mapOfDataSet.keySet();   		Iterator it=s.iterator();     		while(it.hasNext()) {     		String me =""+it.next();       		DataSet objCategory =(DataSet)mapOfDataSet.get(me);   		System.out.println("inside while b4 buffer"+mapOfDataSet.get(me));   		buffer1.append("<dataset seriesName='"+objCategory.getName()+"'>");   				   for(int i=0;i<objCategory.getListOfSet().size();i++){   		buffer1.append("><set value='"+objCategory.getListOfSet().get(i)+"'/>");   				}   		buffer1.append("</dataset>");   						}     		System.out.println("buffer1...."+buffer1.toString());   		return buffer1.toString();   	}  

i m calling all these methods in jsp like this

  1. List list1 = getdata.prepareList(vB_CL_Cust_NPS.getYr4_data(),nps_mn1,vB_CL_Cust_NPS.getSegment4_data(),vB_CL_Cust_NPS.getNps4_data());
  2.  
  3.  Vector data1= getdata.readData(list1);
  4.  
  5. String str2= getdata.prepareCategoriesXML((LinkedHashMap)data1.get(0));
  6. String str3=getdata.prepareDatasetXML((Map)data1.get(1));
  7. String chartXML1 = "<chart connectNullData='1' labelDisplay='Rotate' slantLabels='1' baseFont='Ge Inspira' useRoundEdges='1' legendPosition='RIGHT' clickURL='j-download-DwnNPS-4' yAxisName='NPS' legendBorderAlpha='0' shownames='1' showvalues='0' >";
  8. String chartCatge1 ="<categories>"+str2;
  9. String chartCat1=str3;
  10. /*for(int head1=0;head1<nps1.size();head1++)  
  11. {  
  12. chartCatge1 = chartCatge1 + "><category label='"+nps1.get(head1)+"'/>";  
  13. }*/
  14. chartCatge1 = chartCatge1 +"</categories>";
  15. String strXML1=chartXML1+chartCatge1+chartCat1+"</chart>";
  16.  System.out.println ("STRING XML :"+strXML1);
  17. //Create the chart - Column 3D Chart with data contained in strXML1
  18. String chartCode1= createChart("design/js/FusionCharts/MSLine.swf","", strXML1,"nps2"490200false,true);
  19. System.out.println ("CHART CODE :"+chartCode1);

At last i am geting xml file like this.

<chart connectNullData='1' labelDisplay='Rotate' slantLabels='1' baseFont='Ge Inspira' useRoundEdges='1' legendPosition='RIGHT' imageSave='1' link='javaScriptjr-redface.gif">nClick()I am trying to plot msline chart using msline.swf file in jsp.

but my problem is

 

i have several months as categorie labels.

 

in database for dataset p-tech,i have values according to month dec-2008,mar-2009,apr-2009.

 

but it is ploating on jul-2008,aug-2008,sep-2008 respectivley.

 

The reason is.....

 

Just to reiterate, i am passing category labels as follows:

 

<category label='Jul-2008'/>

<category label='Aug-2008'/>

<category label='Sep-2008'/>

<category label='Oct-2008'/>

<category label='Nov-2008'/>

<category label='Dec-2008'/>

<category label='Mar-2009'/>

<category label='Jun-2009'/>

 

Now, for example, when i am passing the data values for the series "P-Tech", i m passing the set values, which, i assume are to correspond to the categories of Dec, Mar and Jun, is as follows:

 

<set value='0.0'/>

<set value='100.0'/>

<set value='100.0'/>

 

Here, what is happening is that the <set> elements given as input are three in number and thereby they are corresponding to the first three categories in the category list which are that of Jul, Aug and Sep.

 

Here, we need to pass empty <set> elements so that the values, say in the "P-Tech" series, refer/correspond to the correct category label.

 

Foe example:

 

<chart ....... >

<categories>

<category label='Jul-2008'/>

<category label='Aug-2008'/>

<category label='Sep-2008'/>

<category label='Oct-2008'/>

<category label='Nov-2008'/>

<category label='Dec-2008'/>

<category label='Mar-2009'/>

<category label='Jun-2009'/>

</categories>

<dataset seriesName='P-TECH'>

<set />

<set />

<set />

<set />

<set />

<set value='0.0'/>

<set value='100.0'/>

<set value='100.0'/>

</dataset>

..

..

..

<chart/>

 

How to create empty set tags at coresponding positions.

I have each column values in one bean with database order.

 

Let me know any suggestions to do this.

 

Share this post


Link to post
Share on other sites

Hi,

Thanks alot for your reply.

using empty set element i know.

But i want how to identify where we need to create emty set element.

I mean to say,as part of my post i gave the data format which is coming from db.

I am facing prblm while building logic.

I am not able to identify position where i have to creat empty set element.

Its really very urgent,plz help me...... 

Share this post


Link to post
Share on other sites

...

Greetings,

It is somewhat difficult to convey this logic without having a working sample code from your side and without knowing the database schema. So, I am trying to explain the best that I can.

In your method prepareDatasetXML(), you are running a loop in line number 28. What I can see is that this loop iterates through all values present in objCategory.getListOfSet(). This is where you need to modify.

This loop will need to run through all the categories, something like in line 7 of prepareCategoriesXML(). While it runs through this loop, you should also define a counter outside the loop (say, c) starting from 0. Now, while in the loop, you need to check whether the value corresponding to objCategory.getListOfSet().get© is of the same category as ((Category)mapOfCategory.get(me).getLabel();.

If yes, then generate a "<set value='"+objCategory.getListOfSet().get©+"'/>" and increment the outer counter c.

If no, then generate an empty set.

Edited by Guest

Share this post


Link to post
Share on other sites

...

Greetings,

Does your sample code already implement the logic that we had discussed in my previous post? If not, then to speed up the process of our resolution, I would like you to do the same and then re-send me the code.

Share this post


Link to post
Share on other sites

Hi,

Your post tells like compare two values for generating set values.

but

objCategory.getListOfSet().get©,this stmt gives integer values  for example:100,65 etc..

((Category)mapOfCategory.get(me).getLabel(),this stmt gives string whch represents regions

example:CARDIAC,CU-IT,P_TECh etc....

How to compare these values?

Can you please explain this?

Thanks alot in advance.

Share this post


Link to post
Share on other sites

...

Greetings,

You need to check from your database and/or the objCategory object as to what is the corresponding category for each label. IMHO: there is most likely a corresponding category for every item in the region. If the object does not return one, you might need to fetch this data directly from the database by joining related tables.

This is perhaps beyond our scope to help you out directly with the codes. However, if you can figure out the above-mentioned correspondence, we can proceed for a final solution.

Share this post


Link to post
Share on other sites

Hi Anila,

It can be like this:

1. Create a query that results into a recordset of unique/distinct category values using a sort order. Store it into an array. This would help you building the categories.

2. Now, antoher SQL query to fetch dataset records along with the cateogy names with the same sort order.

3. Now iterate through the array as well on each iteration compare the catgory name == array elemet''s value. If so, add that value in SET. Otherwise add blank <SET/> till you find a match.

4. The dataset would be completely built once your loop ends.

Share this post


Link to post
Share on other sites

Anila,

:) :crying:

This is sad  :ermm:

That is not a very good thing from your authority:pinch:. As a developer you should have some right atlest to query the database and store the result in Java.

You might approach .. :arrow:  ... have a bit of discussion :discuss:  with your seniors regarding this .. and we wish things come up smooth :smooooth:

Best of luck from all of us :)

Share this post


Link to post
Share on other sites

Hi,

I tried that also using DOM parser API to build xml.

I am not getting idea to co-relate categeroies wth set values for a particular dataset.

All the data i m putting into one list.

using the setter,getters,i am trying to get data.

like that i am framing categeroies,dataset,set values also.

but here postioning is giving prblm....i mean to say for a particular dataset,does catageroiee have set value or not.

Share this post


Link to post
Share on other sites

...

Greetings,

I am not getting idea to co-relate categeroies wth set values for a particular dataset.

You can co-relate categories with set-values, only when every set-value has a corresponding category field.

Now, you need to ask your DB department to either give you the DataBase Schema or to tell you what is the name of the category column in the table where the set-values are stored.

Once you have the above information, you can compare category of every set-value with the initial set of categories and correspondingly generate your XML as discussed in our previous posts ( http://www.fusioncharts.com/forum/FindPost19187.aspx ).

Share this post


Link to post
Share on other sites

...

Greetings,

For FusionCharts, "set" values have one-to-one linear mapping with categories only. Logically, datasets have no mapping with categories and vice-versa.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now