Select to view content in your preferred language

Charting Toolkit Column Series in a FeatureLayer MapTip?

3840
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
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?


You need to combine the dictionary converter (needed with SL3) and the converter returning 0 when null:
 
public sealed class MyDictionaryConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var dict = value as IDictionary<string, object>;
if (dict != null)
{
if (dict.ContainsKey(parameter as string))
return dict[parameter as string];
}
 
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}




What Should I refresh after it?

I would say : nothing, should be automatic. Is the slider changing the opacity?
0 Kudos
EmilianoDelucia
Deactivated User
Thanks Dominique, I will test the Converter part.

About the layers in the TOC, I'm turning those layers off doing something like "tl.IsChecked = false;" where tl is the TocLayer. It works, because the checks box from each layer are off after that step, but the map doesn't refresh.
The opacity of the service is not changing.
Some idea?

Thanks in advance.
Emiliano
0 Kudos
EmilianoDelucia
Deactivated User
Dominique,
I realized about a problem with the layers on the TOC.
If I try for example:
TOC.TocItem ti = TOC1.Services[0].Children[0];
ti.IsChecked = false;

and I didn't click over any node on the TOC yet, it turn off the layer but doesn't refresh the map.

If first, I click in some node of the TOC, and then execute these two lines of code, it turn off the layer and refresh the map.
For some reason is refreshing the map just only if you clicked in a node before do this steps.

I would like to force this click or find some way to refresh the map after turn off the layer.

Some idea?


Thanks.
Emiliano.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi Emiliano,

From the code, it looks like an event handler is set on the first click :
 
private void ckbVisibility_Checked(object sender, RoutedEventArgs e)
{
CheckBox ckb = sender as CheckBox;
TocItem data = ckb.DataContext as TocItem;
if (ckb.Tag.ToString().ToLower() == "new")
{
ckb.Tag = "";
data.ItemChecked += _itemChecked;
}
}

It's likely the source of your issue.
I guess this would need little change either to initialize the event handler another way or to avoid usage of this event.
My 2 cts :
- remove this event
- make IsChecked virtual in TOCItem
- override IsChecked in TOCLayer and TOCService for doing the job (which is in _itemChecked today)
- use a basic twoway binding between IsChecked and the UI

Note that this sample is not provided by ESRI so you won't modify it from ourself:)
0 Kudos
EmilianoDelucia
Deactivated User
OK Dominique, Thanks, I will try to fix it.

Coming back to the MapTips, I implemented the class MyDictionaryConverter that you gave to me, but I couldn't bind it correctly. It's OK if I do (just with the Converter. I also set others parameters to b2):

Binding b2 = new Binding("");
MyDictionaryConverter dc2 = new MyDictionaryConverter();
b2.Converter = dc2;


Question 2:

I have other question:
Is possible to insert a combobox inside a cell of a DataGrid?, you know, I don't need a Column template with the entire column with combo-boxes (I know how to do it), just I need one combobox in one of the cells from the Data Grid. My idea is to have a column that depending of the type of data that I have (controling it through the code behind), set the content of the column with a text box or with a combobox. I want a mix of those in the same column.
Is that possible?


Thanks!
Emiliano.
0 Kudos
EmilianoDelucia
Deactivated User
Forget about Question 2, I've solved it!!

Thanks.
Emiliano.
0 Kudos
EmilianoDelucia
Deactivated User
I thought I had solved Question 2, but is not working very well :mad:

Please let me know if you know how to do it..

Thanks!
Emiliano
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Binding b2 = new Binding("");
MyDictionaryConverter dc2 = new MyDictionaryConverter();
b2.Converter = dc2;


You need to initialize the ConverterParameter as well:
b2.ConverterParameter = "NEWFIELD";

If this is not working, try debugging the converter by putting a break point in the Convert method in order to figure out the issue.

Is possible to insert a combobox inside a cell of a DataGrid?,

Sorry, I am not used to working with datagrid.
I suggest you to create a new thread with another title, hopefully somebody knows.
0 Kudos
DonFreeman
Emerging Contributor
Hi Dominique -

Using your example I have been able to get this started pretty well.
 <esri:FeatureLayer.MapTip>
                            <Border Background="Pink">
                                <Border.Resources>
                                    <sys:Int32 x:Key="zero">0</sys:Int32>

                                    <ListBox x:Name="_1998">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._1998], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_1999">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._1999], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2000">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2000], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2001">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2001], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2002">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2002], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2003">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2003], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2004">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2004], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2005">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2005], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2006">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2006], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2007">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2007], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2008">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2008], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2009">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2009], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                    <ListBox x:Name="_2010">
                                        <ListBoxItem Content="{Binding [tcmlatestcounts._2010], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                </Border.Resources>
                                <!--<TextBlock Text="{Binding [tcmlatestcounts._1998]}" Foreground="Black" />-->

                                 <toolkit:Chart Title="Historical Counts" Width="800">
                                    <toolkit:Chart.Axes>
                                        <toolkit:CategoryAxis Orientation="X" Foreground="Transparent" />
                                    </toolkit:Chart.Axes>
                                    <toolkit:Chart.Series>
                                        <toolkit:ColumnSeries Title="1998" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _1998}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="1999" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _1999}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2000" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2000}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2001" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2001}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2002" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2002}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2003" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2003}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2004" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2004}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2005" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2005}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2006" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2006}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2007" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2007}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2008" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2008}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2009" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2009}, Path=Items}" />
                                        <toolkit:ColumnSeries Title="2010" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource _2010}, Path=Items}" />
                                    </toolkit:Chart.Series>
                                </toolkit:Chart>
                            </Border>
                        </esri:FeatureLayer.MapTip>

I would like to label each vertical bar with the title (year) that it represents and eliminate the legend. Is there a way to do that?
Thanks
0 Kudos
DonFreeman
Emerging Contributor
Dominique -
Hi again. Further research led me to a different construct for the chart. It now looks like this and is closer to what I wanted.
 <esri:FeatureLayer.MapTip>
                            <Border Style="{StaticResource PanelBorder}">
                                <Border.Resources>
                                    <sys:Int32 x:Key="zero">0</sys:Int32>

                                    <ListBox x:Name="Counts">
                                        <ListBoxItem Name="_1998" Content="{Binding [tcmlatestcounts._1998], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_1999" Content="{Binding [tcmlatestcounts._1999], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2000" Content="{Binding [tcmlatestcounts._2000], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2001" Content="{Binding [tcmlatestcounts._2001], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2002" Content="{Binding [tcmlatestcounts._2002], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2003" Content="{Binding [tcmlatestcounts._2003], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2004" Content="{Binding [tcmlatestcounts._2004], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2005" Content="{Binding [tcmlatestcounts._2005], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2006" Content="{Binding [tcmlatestcounts._2006], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2007" Content="{Binding [tcmlatestcounts._2007], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2008" Content="{Binding [tcmlatestcounts._2008], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2009" Content="{Binding [tcmlatestcounts._2009], TargetNullValue={StaticResource zero}}" />
                                        <ListBoxItem Name="_2010" Content="{Binding [tcmlatestcounts._2010], TargetNullValue={StaticResource zero}}" />
                                    </ListBox>
                                 
                                </Border.Resources>

                                <toolkit:Chart Title="Historical Counts" FontWeight="Bold"  Width="800" Height="400">
                                    <toolkit:Chart.Axes>
                                        <toolkit:CategoryAxis Orientation="X" Title="Year" />
                                        <toolkit:CategoryAxis Orientation="Y" Title="ADT"  />
                                    </toolkit:Chart.Axes>
                                    <toolkit:Chart.Series>
                                        <toolkit:ColumnSeries Title="ADT" IndependentValueBinding="{Binding Name}" DependentValueBinding="{Binding Content}" ItemsSource="{Binding Source={StaticResource Counts}, Path=Items}" />
                                    </toolkit:Chart.Series>
                                </toolkit:Chart>
                            </Border>
                        </esri:FeatureLayer.MapTip>


However, I would still like to remove the legend box. Also, is there a work around for not being able to use a number as the Name? The underscore is unsightly.
0 Kudos