Not able to Bind List in a Tooltemplate

Hi,

I want to bind a list in Tooltip template in a Columnchart. But if i do so , in ios it shows a blank list and in android it crashes.

5 Replies

MP Michael Prabhu M Syncfusion Team September 18, 2018 09:38 AM UTC

Hi Urvashi, 
 
Greetings from Syncfusion, we have tried to replicate the scenario at our end by preparing a simple sample and we are afraid we were not able to reproduce this issue, can you please check the below sample 
 
 
Since we are not aware of your exact application scenario, we were not able to reproduce this issue at our end, can you revert us by modifying the sample above based on your application scenario? so that it will be helpful for us to investigate further and provide you a better solution at the earliest.  
 
Thanks, 
Michael 




UR Urvashi September 18, 2018 09:49 AM UTC

Hi,

I have a Model from that the list values will get binded. I have made modifications to your attached sample and the list there comes blank.
Please look into it asap.

Attachment: BetaReleaseNuget430643229_7911bfe3.zip


MP Michael Prabhu M Syncfusion Team September 19, 2018 11:10 AM UTC

Hi Urvashi, 
 
Thanks for your patience, we have prepared a sample and it can be downloaded from the link below. 
 
 
In the above sample we have achieved your requirement by setting ListView inside a Frame as a TooltipTemplate and the position of the tooltip which you requested in the forum #139917 is also customized by overriding it in the CustomRenderer and setting tooltip position as desired like left, right, top, bottom as like in below code snippet. 
 
Code snippet [XAML]:   
 <chart:BarSeries.TooltipTemplate>
                            <DataTemplate x:Name="template">
                                <Frame WidthRequest="200" HeightRequest="200">
                                    <ListView x:Name="list" ItemsSource="{Binding BarData}" >
                                        <ListView.BindingContext>
                                            <local:ViewModel></local:ViewModel>
                                        </ListView.BindingContext>

                                        <ListView.ItemTemplate>
                                            <DataTemplate>
                                                <ViewCell>
                                                    <StackLayout Orientation="Horizontal">
                                                        <Image Source="icon.png" WidthRequest="30" HeightRequest="40" Margin="0,2,0,0" VerticalOptions="Start" HorizontalOptions="Start" />
                                                        <StackLayout Orientation="Vertical">
                                                            <StackLayout Orientation="Horizontal">
                                                                <Label Text="XValue : "></Label>
                                                                <Label Text="{Binding Category}"></Label>
                                                            </StackLayout>
                                                            <StackLayout Orientation="Horizontal">
                                                                <Label Text="YValue : "></Label>
                                                                <Label Text="{Binding YValue}"></Label>
                                                            </StackLayout>
                                                        </StackLayout>
                                                    </StackLayout>
                                                </ViewCell>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>

                                    </ListView>
                                </Frame>
                            </DataTemplate>
                        </chart:BarSeries.TooltipTemplate>
 
 
Code snippet for Android in MainActivity.cs[C#] 
 
Xamarin.Forms.Forms.ViewInitialized += Forms_ViewInitialized; 
 
 private void Forms_ViewInitialized(object sender, Xamarin.Forms.ViewInitializedEventArgs e)
 {
            if (e.NativeView is SfChart)
            {
                SfChart chart = e.NativeView as SfChart;

                for (int i = 0; i < chart.Behaviors.Count; i++)
                {
                    var tooltip = chart.Behaviors[i] as ChartTooltipBehavior;

                    tooltip.TooltipPosition = ChartElementPosition.Right;
                }
            }
  }
 
  
 
Code snippet for Android in AppDelegate.cs[C#] 
 
 Xamarin.Forms.Forms.ViewInitialized += Forms_ViewInitialized; 
 
 private void Forms_ViewInitialized(object sender, Xamarin.Forms.ViewInitializedEventArgs e)
{
            if (e.NativeView is SFChart)
            {
                SFChart chart = e.NativeView as SFChart;

                for (int i = 0; i < chart.Behaviors.Count; i++)
                {
                    var tooltip = chart.Behaviors[i] as SFChartTooltipBehavior;

                    tooltip.Position = SFChartElementPosition.Right;
                }
           }
}
 
 
 
Hope this helps. 
 
Thanks, 
Michael 



UR Urvashi September 20, 2018 06:48 AM UTC

Hi Micheal,

It works .It's great help .But i am facing small issue.Here the List you have bound works fine.

But I am having a scenario where i am binding one list to my chart .That chart itemsource model object is having one list inside it.That list i need to bind .Will that scenario work?

Let's say in your attached sample you have model 
BarData >> List<TooltipData>

I need to bind List<TooltipData> .Please help me out in this scenario.You have been a great help.


MP Michael Prabhu M Syncfusion Team September 20, 2018 10:49 AM UTC

Hi Urvashi, 
 
Thanks for the update, we have prepared a simple sample for your requirement and it can be downloaded from the link below. 
 
 
Hope this helps. 
 
Thanks, 
Michael 



Loader.
Up arrow icon