Select to view content in your preferred language

Charting Toolkit Column Series in a FeatureLayer MapTip?

3819
27
04-08-2010 08:02 AM
KevinStofan
New Contributor
I'm trying to nest a Column Chart in the MapTip output of a FeatureLayer. The three ColumnSeries in the markup below are three ways I have tried to get this to work. No errors come up in debug, but the graph does not display any data or populate the axes. TEL_TOT, MOB_TOT, and INT_TOT refer to OutFields of the FeatureLayer. Can this even be done with out any code behind? Any help would be greatly appreciated.

<chartingToolkit:Chart Title="Communication">
    <chartingToolkit:Chart.Series>
        <chartingToolkit:ColumnSeries
            Title="Telephone Users"
            ItemsSource="{Binding Converter={StaticResource FeatureDictionaryConverter},
                ConverterParameter=TEL_TOT, Mode=OneWay}"
            IndependentValueBinding="{Binding Key}"
            DependentValueBinding="{Binding Value}"/>
        <chartingToolkit:ColumnSeries
            Title="Mobile Users"
            ItemsSource="{Binding Converter={StaticResource FeatureDictionaryConverter},
                ConverterParameter=MOB_TOT, Mode=OneWay}"
            IndependentValuePath="Key"
            DependentValuePath="Value"/>
        <chartingToolkit:ColumnSeries
            Title="Internet Users"
            ItemsSource="{Binding Converter={StaticResource FeatureDictionaryConverter},
                ConverterParameter=MOB_TOT, Mode=OneWay}"
            IndependentValueBinding="{Binding Key}"
            DependentValueBinding="{Binding Value}" />
    </chartingToolkit:Chart.Series>
</chartingToolkit:Chart>
0 Kudos
27 Replies
DominiqueBroux
Esri Frequent Contributor
The ItemsSource of a chart needs to be an Enumerable (e.g a collection). Then the implicit binding to define DependentValue and IndependentValue is one item of this collection.

In your case, depending of the graphical expected result, you could need either 3 collections of one item, or one collection of 3 items.

Since it's probably better you to implement your own collection, you can also use an existing Collection such as a Listbox.

In the resources :
   . declare one Listbox by serie
   . add the members of the serie as ListBoxItem
In the chart:
   . bind ItemsSource to Items property of your Listbox (Listbox is not Enumerable by itself --> need Items)
   . bind DependentValue to content property of the ListboxItems

See code behind and attached result.

                <esri:FeatureLayer.MapTip>
                    <Border Background="{StaticResource CommonBackgroundBrush}">
                        <Border.Resources>
                            <ListBox x:Name="Telephones">
                                <ListBoxItem Content="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=TEL_TOT}" />  <!--with SL4 : {Binding [TEL_TOT]}-->
                            </ListBox>
                            <ListBox x:Name="Mobiles">
                                <ListBoxItem Content="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=MOB_TOT}" />  <!--with SL4 : {Binding [MOB_TOT]}-->
                            </ListBox>
                            <ListBox x:Name="Internets">
                                <ListBoxItem Content="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=INT_TOT}" />  <!--with SL4 : {Binding [INT_TOT]}-->
                            </ListBox>
                        </Border.Resources>
                        <chartingToolkit:Chart Title="Communication">
                            <chartingToolkit:Chart.Series>
                                <chartingToolkit:ColumnSeries Title="Telephone Users" DependentValueBinding="{Binding Content}"
                                                              ItemsSource="{Binding Source={StaticResource Telephones}, Path=Items}" />
                                <chartingToolkit:ColumnSeries Title="Mobile Users" DependentValuePath="Content"
                                                              ItemsSource="{Binding Source={StaticResource Mobiles}, Path=Items}" />
                                <chartingToolkit:ColumnSeries Title="Internet Users" DependentValuePath="Content"
                                                              ItemsSource="{Binding Source={StaticResource Internets}, Path=Items}" />
                            </chartingToolkit:Chart.Series>
                        </chartingToolkit:Chart>
                    </Border>
                </esri:FeatureLayer.MapTip>


Dominique
0 Kudos
KevinStofan
New Contributor
Dominique,

Thanks. This was a huge help. Your example is exactly how I needed it to look.
0 Kudos
EmilianoDelucia
Deactivated User
Dominique,
I have a problem trying to update the binding by code inside a FeatureLayer. For example I have this Feature Layer in the XAML:

<esri:FeatureLayer ID="ChartFLayer" x:Name="ChartFL"
            FeatureSymbol="{StaticResource ProductionMarkerSymbol}">
                <esri:FeatureLayer.OutFields>
                    <sys:String>PROD_ACUM</sys:String>
                </esri:FeatureLayer.OutFields>
                <esri:FeatureLayer.MapTip>
                    <Border Style="{StaticResource MapTipBorder}">
                        <Grid Height="160" Width="160">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="50"/>
                                <RowDefinition Height="80"/>
                            </Grid.RowDefinitions>
                            <TextBlock Margin="5,0,0,0" Text= "Prod: " Foreground="White"/>
                            <TextBlock Margin="25,0,0,0" x:Name="txtProd"  Foreground="White" Text="{Binding Converter={StaticResource MyDictionaryConverter},ConverterParameter=PROD_ACUM, Mode=OneWay}" />

                                                  </Grid>
                    </Border>
                </esri:FeatureLayer.MapTip>
            </esri:FeatureLayer>


I want to update by code the ConverterParameter PROD_ACUM in txtProd, but I cant!
First problem:
   txtProd is null when I try to add a binding by code.
Second Problem:
  If I try creating a new TextBlock instance and changing the binding like this code below, it doesn't work:

               FeatureLayer ChartFeaturelayer = MyMap.Layers["ChartFL"] as FeatureLayer;
               ChartFeaturelayer.OutFields.Add("NEWFIELD"]);
               txtIDChart = new TextBlock(); 
                Binding b = new Binding("");
                b.Mode = BindingMode.OneWay;
                b.ConverterParameter = "NEWFIELD";
               
                txtIDChart.SetBinding(TextBlock.TextProperty, b);

                txtIDChart.UpdateLayout();


Thanks in advance.
Emiliano.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

First problem:
txtProd is null when I try to add a binding by code.

The maptip is not in the same namescope. You should be able to get it by :
TextBlock txtBlock = ChartFeaturelayer.MapTip.FindName("txtProd") as TextBlock;



Second Problem:
If I try creating a new TextBlock instance and changing the binding like this code below, it doesn't work:

FeatureLayer ChartFeaturelayer = MyMap.Layers["ChartFL"] as FeatureLayer;
ChartFeaturelayer.OutFields.Add("NEWFIELD"]);
txtIDChart = new TextBlock();
Binding b = new Binding("");
b.Mode = BindingMode.OneWay;
b.ConverterParameter = "NEWFIELD";

txtIDChart.SetBinding(TextBlock.TextProperty, b);


You forgot to initialize the converter:
b.Converter = new DictionaryConverter();


Note : il you are using SL4, you don't need the dictionary converter anymore:
 
Binding b = new Binding("[NEWFIELD]");
0 Kudos
EmilianoDelucia
Deactivated User
Great, I solved that thanks your help!

One more question. In the Chart that you did for kastofan, is there the possibility to take out the number "1" that is in the bottom?, is there a property to configure the x-axis label or something like that?

Thanks!
0 Kudos
EmilianoDelucia
Deactivated User
Sorry, I forgot to ask you something else.
In the same case (kastofan chart) if the value of the field TEL_TOT in the database is null, the application is giving an error (attaching it).
Is there a possibility to prevent that? or control it?

Thanks.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
In the same case (kastofan chart) if the value of the field TEL_TOT in the database is null, the application is giving an error (attaching it).
Is there a possibility to prevent that? or control it?


You could use a null value converter or, with SL 4, use the TargetNullValue binding attribute:

<Border.Resources>
<sys:Int32 x:Key="zero">0</sys:Int32>
<ListBox x:Name="Telephones">
<ListBoxItem Content={Binding [TEL_TOT], TargetNullValue={StaticResource zero}}" />
</ListBox>
<ListBox x:Name="Mobiles">
<ListBoxItem Content={Binding [MOB_TOT], TargetNullValue={StaticResource zeo}}" />
</ListBox>
<ListBox x:Name="Internets">
<ListBoxItem Content={Binding [INT_TOT], TargetNullValue={StaticResource zero}}" />
</ListBox>
</Border.Resources>




is there the possibility to take out the number "1" that is in the bottom?, is there a property to configure the x-axis label or something like that?



You can make transparent the x-Axis label:
 
<chartingToolkit:Chart Title="Communication" >
<chartingToolkit:Chart.Axes>
<chartingToolkit:CategoryAxis Orientation="X" Foreground="Transparent" />
</chartingToolkit:Chart.Axes>
....

You can also change the style using Blend.
0 Kudos
EmilianoDelucia
Deactivated User
Thank you very much!, I will test it.

Thanks for you help.
Emiliano.
0 Kudos
EmilianoDelucia
Deactivated User
Hi Dominique,
Finally, I was able to take out the X-axis label, but I couldn't implement a null converter in SL3, because like you said TargetNullValue is available in SL4.
Could you explain to me how to do it?

Other Question.
After Load the graphics I'm turning off some layers in the TOC by code (implemented the ESRI Gallery Example of the TOC).
After turned off the layers the map doesn't refresh the changes, I still seeing all the layers on the map, but my TOC has the check-box from those layers unchecked.
What Should I refresh after it? I've tried to refresh the map service, the TOC layout, etc, but I can't get my map refreshed.


Thanks a lot!
Emiliano.
0 Kudos