How to draw pie chart using aspmap.4.7 ?

5/23/2013 7:50:08 AM
Total Posts 23

How to draw pie chart using aspmap.4.7 ?

I have the different data at database which is to show from pie chart. I get the data from database as DataTable, but how to load these data in pie chart using aspmap 4.7  in c#.NET ?

5/23/2013 8:26:15 AM
MVP
Total Posts 323

Re: How to draw pie chart using aspmap.4.7 ?

You have to use the AspMap.DataSource class instead of data tables to add a relate from a map file to a database table. There is the ChartMapApp sample in AspMap 4.7:

AspMap.Layer layer = map.AddLayer(MapPath("states.shp"));
AspMap.DataSource dataSource = new AspMap.DataSource();
dataSource.ConnectionString = "Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes";
dataSource.CommandText = "SELECT * FROM demography";

if (!layer.AddRelate("STATE_ABBR", dataSource, "STATE_ABBR"))
     throw new Exception("Cannot add a relate");

AspMap.ChartRenderer chartRenderer = layer.ChartRenderer;
chartRenderer.Add("POP1990", Color.Red);  // POP1990 is from the SQL Server database
chartRenderer.Add("POP1997", Color.Green); // POP1997 is from the SQL Server database
chartRenderer.ChartType = ChartType.Pie;
chartRenderer.MinPieSize = 40;
chartRenderer.MaxPieSize = 60;            

5/23/2013 11:36:18 AM
Total Posts 50

Re: How to draw pie chart using aspmap.4.7 ?

Now I have the same problem. If database also come from SQL but I use this SQL query : "Select Count(Customer) from DBcustomer group by DMA" how to make this pie chart?
5/23/2013 12:40:03 PM
MVP
Total Posts 323

Re: How to draw pie chart using aspmap.4.7 ?

A proper Select statement should return a column with unique values which will be linked by AddRelate with the same column in the map layer. The Select in the sample above returns a recordset with the STATE_ABBR (state abbreviations) column which uniquely identifies each state. The 'states' layer also has a STATE_ABBR column.

Select Count(..) probably cannot be used, it returns a single record without a column that can be used as the key column.

5/24/2013 2:18:47 AM
Total Posts 23

Re: How to draw pie chart using aspmap.4.7 ?

I am using MySQL database..

Database table is DrinkingSources and fields are District(TEXT),TapePiped(DOUBLE),WellTubeWell(DOUBLE)

and nepal.shp has Attributes are DISTRICT, and so on....not worked...

my code is in C#.NET

AspMap.Layer layer = map.AddLayer(Server.MapPath("~/Maps/") + "nepal.shp"); ;
AspMap.DataSource dataSource = new AspMap.DataSource();
dataSource.ConnectionString = @"Provider=SQLNCLI10;server=localhost;user id=root;database=cencus; charset=utf8";
dataSource.CommandText = "select * from DrinkingSources";

//DataTable dt = cBll.GetHealth(2001,"");
if (!layer.AddRelate("District", dataSource, "DISTRICT"))
throw new Exception("Cannot add a relate");

//AspMap.Layer layer = map["nepal"];
AspMap.ChartRenderer chartRenderer = layer.ChartRenderer;

chartRenderer.Add("TapePiped", Color.Red);
chartRenderer.Add("WellTubeWell", Color.Green);

chartRenderer.ChartType = AspMap.ChartType.Pie;
chartRenderer.MinPieSize = 40;
chartRenderer.MaxPieSize = 60;
chartRenderer.OutlineColor = Color.Black;
chartRenderer.OutlineWidth = 1;

 

5/24/2013 3:31:38 AM
MVP
Total Posts 323

Re: How to draw pie chart using aspmap.4.7 ?

MySql does not have an OLEDB provider that can be used with AspMap.DataSource.

 

We are working on support for data tables, it will be available in next releases.

5/28/2013 12:05:00 AM
MVP
Total Posts 323

Re: How to draw pie chart using aspmap.4.7 ?

The AddRelate method now supports the DataTable class in AspMap 4.8.2