ThinkGeo.com    |     Documentation    |     Premium Support

Create ZedGraph Chart using My Own Data

Hi All,


In MapSuite 3.0 Samples ZedGraph sample was given, but it was based on the data which is in shape file.


But my requirement is i want to prepare ZedGraph chart based on  data coming from database.


and i have my own shape file.


 


Its urgent.


Thanking you.


 



Mahender, 
  
   I think I can help but I need a clarification.  Which is your case? 
  
 1. The shape file might have the points for where you want to show the charts but the main data for the charts is in a SQL Database? 
  
 2. The shape data and the chart data is in a SQL database and the database has Spatial Extensions such as SQL 2008 or Oracle Spatial.  If so which brand? 
  
 The good news is that in either case the main this you will want to do is put code in the ZedGraphDrawing event.  You will have to first when you setup the style make sure to specify that you need the Id of the feature back or some kind of identifier to match the Feature to the data in your SQL database.  Something like zedGraphStyle.RequiredColumnNames.Add("MyIdColumn");  Then when the event raised you can get this value back from the feature using code like e.Feature.ColumnValues["MyIdColumn"].ToString;.  With the Id in hand you can go to you your database and get whatever data you wish.  If this is too slow to make lots of SQL queries like this then you need to override the ZedGraphStyle.  if you need to do this let me know and we can help you through it. 
  
 David 
  


Hi David,


Thanks for your response.


 


I have the points for where you want to show the charts but the main data for the charts is in a SQL Database.


but i have a small doubt , let us take a small example i have a shape file having states ,


and i got the each states data from the sql database, then i have points in my shape file, but how can i map this data belongs to this state?


 


 



Mahender,


To make it clear, let’s make it more specific, say there is no column in my states shape file, and there are whole bunch of columns like “Name”, “Pop”, “Area” in my SQL database, so
1, if I want to display the population in plain text, I need to hook up the CustomColumnFetch event and use that “Pop” field directly in my text style. In the event handler method, I need to get the corresponding field by Feature.ID from the sql database and set it to e.ColumnValue. (See samples -> Feature Layers ->AddMyOwnCustomDataToAFeatureLayer)
 
2, if I want to display the population using a bar or pie graph, I need to hook up both the CustomColumnFetch and ZedGraphDrawing events, use the property zedGraphStyle.RequiredColumnNames.Add(“Pop”) just like that column exists in my shape file; in the CustomColumnFetch handler method, I get the real data from SQL database and set it to features, like what the 1st scenario does.
 
Here is a sample for the second scenario (I didn’t connect to a Sql database, just change the data artificially in the CustomColumnFetch handler method),  please let me know any queries.


Thanks,


Ben



305-ShowBarsWithCustomData.zip (13.6 KB)