Select to view content in your preferred language

Help with a simple Line Chart

3287
20
03-09-2011 12:48 PM
JoshV
by
Regular Contributor
Hello All-

I have a simple Silverlight Application that uses a Timeline and I just want to put in a simple Line Chart above the timeline that will dynamically change if possible.  I've been looking at this link (http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html) but in the Line Series Section for the XAML I do not understand how they are passing the values to the chart.  Does anyone have any good examples of code that show the chart linked to a layer in the Map?

Many Thanks,
0 Kudos
20 Replies
JoshV
by
Regular Contributor
You feature layer ID is WellsFeatureLayer (not WellsLayer).

 
Path=Layers[WellsFeatureLayer].Graphics


Hi Dominique-  If I set it to WellsFeatureLayer then I get the attached error message (picture attached).  It states an Object Reference is not set.  Did I declare the WellsFeatureLayer correctly or did I need to publish my MapService as something more than just a MapService?

 <esri:FeatureLayer ID="WellsFeatureLayer" Url="http://serverprd02/ArcGIS/rest/services/SilverLightDir/Wells_Timeline/MapServer/0" />
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You need to initialize the OutFields property of your feature layer :
OutFields="*"     or OutFields="EOM,Adj_Close"

Sorry, I should have noticed that at your previous post but I missed the point.
0 Kudos
JoshV
by
Regular Contributor
You need to initialize the OutFields property of your feature layer :
OutFields="*"     or OutFields="EOM,Adj_Close"

Sorry, I should have noticed that at your previous post but I missed the point.


You beat me to the response 😉  Here is what I was typing..  If I add the below code where I declare my FeatureLayer and run my App I do not get the error above but when I select anything in the App I just get an hour glass.  any idea why I get an hour glass?  I'll keep testing

<esri:FeatureLayer ID="WellsFeatureLayer" Url="http://serverprd02/ArcGIS/rest/services/SilverLightDir/Wells_Timeline/MapServer/0" >
                <esri:FeatureLayer.OutFields>
                    <sys:String>EOM</sys:String>
                    <sys:String>Adj_Close</sys:String>
                </esri:FeatureLayer.OutFields>
            </esri:FeatureLayer>
0 Kudos
DominiqueBroux
Esri Frequent Contributor

any idea why I get an hour glass?

Perhaps just slow because too much objects in the chart. How many features in your layer?
If it's the case, the filtering by timeextent will help.
0 Kudos
JoshV
by
Regular Contributor
Perhaps just slow because too much objects in the chart. How many features in your layer?
If it's the case, the filtering by timeextent will help.


The WellsFeatureLayer has 2,551 features is that too many?  I tried commenting all the code in the codebehind out like you mentioned yesterday so I'm just using the code in XAML but it still locks up.  I will uncomment all the codebehind code you provided me and wait a few more seconds before selecting anything in the Map to see if that works.  My TimeSlider control is called MyTimeSlider so where you have this line in the codebehind does it need to say "== MyTimeSlider" or "== TimeEvent"?

if (e.PropertyName == "TimeEvent")
                SetLastObservations();


Also I attached my MainPage.XAML.cs as a text file in case you see any issues.  

Best regards,
0 Kudos
DominiqueBroux
Esri Frequent Contributor

does it need to say "== MyTimeSlider" or "== TimeEvent"?

"TimeEvent" : it's the name of the map property which has changed.



public void TemporalRendererTracks()
{
InitializeComponent();
DataContext = this;
}

TemporalRendererTracks was the name of the sample class.
Remove that code and complete your class constructor:
 
public MainPage()
        {
            InitializeComponent();
            DataContext = this;  
        }




return from g in graphics
where g.TimeExtent.Intersects(map1.TimeExtent)
group g by g.Attributes["EOM"] into grp
select grp.OrderByDescending(g => g.Attributes["EOM"]).First();


In your case, you don't need the 2 last lines (useful to get the last observation corresponding to an ID). Try with just :
 return from g in graphics
where g.TimeExtent.Intersects(map1.TimeExtent);
0 Kudos
JoshV
by
Regular Contributor
I trimmed down my Wells Feature class to just 5 Wells and republished my service and the App will run and the Chart displays.  The Chart seems static though and shows all records at once so I'm not sure what's going on there.  I didn't think 2000 records would be that much for this to handle so I guess I will try to add the full 2000 record Wells layer as a layer and have the Chart pull off of a simplified Wells layer (maybe 20 records) in that same service.  Thoughts?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

The Chart seems static though

Check with the debugger that SetLastObservations is being called when the time extent changed.


I didn't think 2000 records would be that much for this to handle

It's likely only an optimization matter.
A chart can handle 2000 objects but with this binding ItemsSource="{Binding ElementName=MyMap, Path=Layers[MyHurricaneFeatureLayer].Graphics}",  as Graphics is an observable collection, the chart is reinitialized each time a graphic is added to the feature layer so 2000 times in your case.
Hovever the timeextent filtering should reduce this number. How many features are displayed at a time?

If you have too ma,y features, you can optimize by replacing the ObservableCollection by a simple collection (IEnumerable) and by firing by yourself the PropertyChanged event each time the collection changed (or another option is to use a dependency property, up to you).
0 Kudos
JoshV
by
Regular Contributor
Hi Dominique-  I found out why nothing was drawing on my Chart after repointing my data back to the 2000 record Wells Feature Class.  The If Statement in map1_PropertyChanged was never entering SetLastObservations(), so I changed the If condition to where it does enter SetLastObservations.  But now I'm getting an error inside SetLastObservations inside the foreach loop.  The error is attached.  Do I need to actually have a graphics layer present in my Map?  Could that be what is causing the error?
0 Kudos
JoshV
by
Regular Contributor
Check with the debugger that SetLastObservations is being called when the time extent changed.


It's likely only an optimization matter.
A chart can handle 2000 objects but with this binding ItemsSource="{Binding ElementName=MyMap, Path=Layers[MyHurricaneFeatureLayer].Graphics}",  as Graphics is an observable collection, the chart is reinitialized each time a graphic is added to the feature layer so 2000 times in your case.
Hovever the timeextent filtering should reduce this number. How many features are displayed at a time?

If you have too ma,y features, you can optimize by replacing the ObservableCollection by a simple collection (IEnumerable) and by firing by yourself the PropertyChanged event each time the collection changed (or another option is to use a dependency property, up to you).


After debugging multiple times, it appears that the program always errors when adding the graphics to LastObservations.  I've tried it with a FeatureClass that only has 5 records and I've tried it with my original FeatureClass of 2000 records but always errors at
LastObservations.Add(g);


Funny thing is that on the Chart, the Date for the first feature will appear in my X-Axis but no line graph is drawn and then the error occurs.  It's very close it seems to working.  I deeply appreciate all your help Dominique and look forward to hearing from you.

-Regards,
0 Kudos