We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ChartToolTipBehavior LabelFormat

Hi,

I have a DateTimeAxis as the PrimaryAxis  and a NumbericAxis as the SecondaryAxis.  How do I display the DateTime and Values in the tooltip ?  
Ii have the code below but it is not displaying the Date and Time.   Thank you.

chartTop.Behaviors.Add(new ChartTooltipBehavior() { LabelFormat = "dd/MM/yy hh:mm" });


1 Reply

PS Parthiban Sundaram Syncfusion Team October 2, 2017 04:46 AM UTC

Hi Albert, 
  
Thanks for using Syncfusion products. 
  
You can achieve this requirement by overriding the GetView method in ChartTooltipBehavior class. Please refer the following code snippet for more details. 
  
Code Snippet: 
 
   protected override View GetView(TooltipView tooltipView) 
        { 
            LinearLayout rootLayout = new LinearLayout(Chart.Context); 
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 
                    LinearLayout.LayoutParams.MatchParent); 
            rootLayout.Orientation = Orientation.Vertical; 
            rootLayout.LayoutParameters = layoutParams; 
            TextView xLabel = new TextView(Chart.Context); 
            string date = (tooltipView.ChartDataPoint as DataModel).XValue.ToString(); 
            var doubleToDate = DateTime.FromOADate(Convert.ToDouble(date)); 
            var formattedDate = doubleToDate.ToString("dd/MM/yy hh:mm"); 
            xLabel.Text = "Date:" + formattedDate.ToString(); 
            xLabel.TextSize = 15; 
            xLabel.SetTextColor(Color.White); 
            TextView yLabel = new TextView(Chart.Context); 
            yLabel.Text = "YValue: " + (tooltipView.ChartDataPoint as DataModel).YValue.ToString(); 
            yLabel.TextSize = 15; 
            yLabel.SetTextColor(Color.White); 
            rootLayout.AddView(xLabel); 
            rootLayout.AddView(yLabel); 
            tooltipView.AddView(rootLayout); 
            return tooltipView; 
        } 
  
We have prepared the sample based on your requirement. Please download the sample from following location. 
  
  
Please let us know, if you need further assistance on this. 
  
Regards,
Parthiban S
 


Loader.
Up arrow icon