Jump to content
Software FX Community

A Simple Map question - How to use a business object as a datasource


dstarkey
 Share

Recommended Posts

I have a map of the US DMA areas (Market Areas, ie NY = 001, LA = 002 etc).  Now I would like the chart and map to work together to display the data on the Map.  I created a very simple Business object (based off of your PassingData example) that I wanted to use for the charts data, and then plot this data on the Map.

For example:

dma_001_--_New_York_NY 1

dma_002_--_Los_Angeles_CA 10

dma_003_--_Chicago_IL 100This works fine when I retrieve these same values from a Text file in the AppData folder (similar to your WorldPopulation sample). So I know that the map should can display the items.  I created a very simple class called DMA, as above the class has two properties Name, and Count to simulate my TextFile. Then I create an array of these DMA items, just like your PassingData sample application.  But I get a TargetException Error when I try to assign the Chart1.DataSource property in the same fashion that your PassingData solution employs.  Both of these throw the same error.

Chart1.DataSourceSettings.DataSource = lstProvider;

Chart1.DataSource = lstProvider;

Here is your sample code from the PassingData solution using a business object:

Chart1.Gallery = Gallery.Bar;

/* Chart FX also supports reading data from a Business Object. In this case, we have created a class containing the

* data (DMA) and used the ListProvider to populate Chart FX with multiple instances of the class.

* Chart FX also supports direct databinding to business object, using the Smart Tag Data Wizard. Please refer to the

* .NET documentation to create a business object that can be used as a data source.*/

DMA[] dmas = new DMA[3];

dmas[0] =

new DMA("dma_001_--_New_York_NY ", 15);

dmas[1] =

new DMA("dma_002_--_Los_Angeles_CA ", 0);

dmas[2] =

new DMA("dma_003_--_Chicago_IL", 20);

ListProvider lstProvider = new ListProvider(dmas);

Chart1.DataSourceSettings.DataSource = lstProvider;

This displays fine as a chart.  But when I try to display those items on a map, in this case Chicago Market should have 20 items I get the error. Here is the method that throws this error modeled from the code above that works.

Map1.MapSource = "C:\\Maps svg\\USA_DMA_v1.svg";

DMA[] dmas = new DMA[211];string text;for (int i = 0; i < Map1.VisibleMapRegions.Count; i++){

text = Map1.VisibleMapRegions.DisplayText;

switch (i)

{

case 0:

case 1:

case 2:

dmas =

new DMA(text, 1000);

break;default:

dmas =

new DMA(text, 0);

break;

}

}

ListProvider lstProvider = new ListProvider(dmas);

 

Chart1.DataSourceSettings.DataSource = lstProvider;

//Chart1.DataSource = lstProvider;

 l checked the Name value of the DMA object and it is correct. The code above was written to test plotting out certain regions within the map.  In the case ab ove I simply wanted NY, LA, and Chicago's corresponding Total to be at 1000, and every other region to have a data value of 0.  What am I missing???  This should be very easy to do but I cannot find out any additional information about:

* Chart FX also supports direct databinding to business object, using the Smart Tag Data Wizard. Please refer to the

* .NET documentation to create a business object that can be used as a data source.*/

 I really need someones help on this.  It is GREATLY APPRECIATED.  Just to reiterate, I can display the map properly opening the file as a tab delimeted text file.  It is when I try to assign the DataSource to a simple Business Object that will not work.  What am I missing????  This should be an easy task.

Thanks,

Don

Link to comment
Share on other sites

Hello, Now my map is not coloring my map regions.  I have figured out my previous problem but am still only half way there.  It seems that my DMA array size needed to be 210 rather than 211.  Now I am having a different issue, the same code that I used before to color my map will not work.  Each Point property is set to -1, and the only thing that displays is a dark blue dma map of the US.  I see that the datasource (DMA object list)  is bound properly, because when I step through the code I see NY has a value of 1000, Chicago likewise etc.... However, instead of coloring the map region red (values of 1000) which is my intention, the whole map is colored dark blue.  Which I believe is the default.  Why would the map behave differently and not color these point attributes??? Is there any way to assign the Point property of the DataItem???  Please help.  Here is my code for the entire Method.

private void LoadDMAChart()

{

AssignConditionalAttributes();

//dma_001_--_New_York_NY 1

//dma_002_--_Los_Angeles_CA 1

//dma_003_--_Chicago_IL 100Chart1.AllSeries.Link.Url = "Default.aspx?Region=$DataText";

Map1.MapSource =

"C:\\Maps svg\\USA_DMA_v1.svg";DMA[] dmas = new DMA[210];

string text;int pnt;for (int i = 0; i < Map1.VisibleMapRegions.Count; i++)

{

text = Map1.VisibleMapRegions.DisplayText;

pnt = Map1.VisibleMapRegions.Point;

//Map1.VisibleMapRegions.Point = i;switch (i)

{

case 0:

case 1:case 2:

case 3:dmas = new DMA(text, 1000);

break;case 10:

case 11:case 12:

case 13:dmas = new DMA(text, 100);

break;case 30:

case 31:case 32:

case 33:dmas = new DMA(text, 30);break;

 

default:dmas = new DMA(text, 0);break;

}

}

ListProvider lstProvider = new ListProvider(dmas);

 

Chart1.DataSourceSettings.DataSource = lstProvider;

//Chart1.DataSource = lstProvider;int total = 0;for (int i = 0; i < Map1.VisibleMapRegions.Count; i++)

{

total = (

int)Chart1.Data[0, i];switch (total)

{

case 0:

Map1.VisibleMapRegions.PointAttributes.Color =

Color.Orange;break;

case 30:Map1.VisibleMapRegions.PointAttributes.Color = Color.Blue;

break;case 5:

case 100:Map1.VisibleMapRegions.PointAttributes.Color = Color.Violet;

break;case 3:

case 1000:Map1.VisibleMapRegions.PointAttributes.Color = Color.Red;

break;default:

Map1.VisibleMapRegions.PointAttributes.Color =

Color.White;break;

}

}

}

 

Everything seems to be working except for the coloring.  Please help, cannot figure this out especially since it works from the text data source.  The only diffirence that I can see is that the text file starts with the first item, whereas the object data source starts at index 0.  Below is the first few lines of my text document that works.

 

DMA Count

dma_001_--_New_York_NY 1

dma_002_--_Los_Angeles_CA 1

dma_003_--_Chicago_IL 100

dma_004_--_Philadelphia_PA 1

dma_005_--_San_Francisco_CA 1

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...