TransWikia.com

Creating Chart in Silverlight that is bound to Layer in Map

Geographic Information Systems Asked on April 29, 2021

I have a simple Silverlight Application that has a Map control that shows a ESRI Tiled layer service and a Dynamic Layer service. The Dynamic Layer service is just called "Wells" and it has a "Date" column and "Gas_Percent" field that would be perfect to show in a Chart.

Does anyone know how I can do this?

I’ve been looking at these examples in below hyperlink (for LineSeries) (Silverlight Chart Examples) but I don’t know how to use my Wells layer and Date and Gas_Percent columns in place of what they have.

One Answer

I did a similar kind of thing some time back. I did this for a featurelayer/graphics layer using ESRI ArcGIS API

Binding the feature/graphics layer attributes to a data grid (did not use the featuredata grid ESRI provides) Then bind a specific grid column to a chart. Infact the way I did was the user can click on a column and the chart would display that column (simple bar chart). So you click a different column the chart changes.


This is how i did it C# code I have a method which executes a GP task that returns a graphics layer I iterate each graphic, create an observable collection and bind the observable collection to the data grid. there are other ways to bind but this worked for me when used with the chart.

    // GP task that returns graphics
    public void Execute(object parameter)
    {
        Geoprocessor getData = new Geoprocessor();
        getData.Url = "GP task URL...";
        getData.Failed += this.GP_Failed;
        getData.GetResultDataCompleted += this.GP_GetResultDataCompleted;
        getData.GetResultDataAsync(this.jobId, "parameter");            
    }

    // The event raised when GP task successful
    void GP_GetResultDataCompleted(object sender, GPParameterEventArgs e)
    {
        object attributeValue = null;

        // Internal class object
        CategoryAttributes categoryAttributes = new CategoryAttributes();

        if (e.Parameter is GPFeatureRecordSetLayer)
        {
            GPFeatureRecordSetLayer gpLayer = e.Parameter as GPFeatureRecordSetLayer;
         
            // Create a new graphics layer
            GraphicsLayer graphicsLayer = new GraphicsLayer();
            graphicsLayer.ID = "GraphicsLayer";

            // Add the graphics to the graphics layer and an observable collection that is binded to a data grid
            foreach (Graphic graphic in gpLayer.FeatureSet.Features)
            {
                CategoryAttribute categoryAttribute = new CategoryAttribute();

                attributeValue = g.Attributes.Where(x => x.Key.Contains("CategoryCount")).SingleOrDefault().Value;
                if (attributeValue != null)
                {
                    categoryAttribute.Count = attributeValue.ToString();
                }

                attributeValue = g.Attributes.Where(x => x.Key.Contains("CategoryValue")).SingleOrDefault().Value;
                if (attributeValue != null)
                {
                    categoryAttribute.Value = attributeValue.ToString();
                }

                attributeValue = g.Attributes.Where(x => x.Key.Contains("CategoryAmount")).SingleOrDefault().Value;
                if (attributeValue != null)
                {
                    categoryAttribute.Amount = attributeValue.ToString();
                }
                categoryAttributes.Add(categoryAttribute);

                graphicsLayer.Graphics.Add(graphic);
            }

            // Add to map
            this.myMap.Layers.Add(graphicsLayer);

            // Bind data to data grid
            this.MyDataGrid.ItemsSource = categoryAttributes;
        }
    }

    // Internal classes for creating the observable collection
    internal class CategoryAttributes : ObservableCollection<CategoryAttribute>
    {
    }
    internal class CategoryAttribute
    {
        public double CategoryCount { get; set; }
        public double CategoryValue { get; set; }
        public double CategoryAmount { get; set; }
    }        

Answered by user2294 on April 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP