ItemToolTipOpening is never been called

5 posts, 0 answers
  1. Markus Demmler
    Markus Demmler avatar
    5 posts
    Member since:
    Mar 2010

    Posted 05 Apr 2010 Link to this post

    Hello,
    I am trying to setup a data drill down simiar to the provided example. But I am facing the problem that the ItemToolTipOpening event is not fired when I place the mouse on a chart point.
    Here is the code that I am using:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Data; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Imaging; 
    using System.Windows.Shapes; 
    using Telerik.Windows.Controls.Charting; 
    using AppointmentScheduler; 
    using Telerik.Windows.Data; 
    using System.Globalization; 
    using Telerik.Windows.Controls; 
     
    namespace AppointmentSchedulerUI 
        /// <summary> 
        /// Interaction logic for ChartWorkingHours.xaml 
        /// </summary> 
        public partial class ChartWorkingHours : Window 
        { 
            private AppointmentScheduler.AppointmentScheduler m_AppointmentScheduler; 
            private Dictionary<string, Employee> m_Employees; 
     
     
            public ChartWorkingHours(Dictionary<string, Employee> employees, AppointmentScheduler.AppointmentScheduler appointmentScheduler) 
            { 
                m_AppointmentScheduler = appointmentScheduler; 
                m_Employees = employees; 
     
                InitializeComponent(); 
                CountriesBox.ItemsSource = employees.Values; 
     
                m_CB_Year.ItemsSource = new int[]{2009, 2010, 2011, 2012};             
                 
                List<string> monthNames = new List<string>(); 
                monthNames.Add("Komplettes Jahr"); 
                for (int i=1; i<=12; i++) 
                    monthNames.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(i)); 
                m_CB_Month.ItemsSource = monthNames;             
     
                m_RadChart.DefaultView.ChartLegend.Header = ""
                m_RadChart.DefaultView.ChartLegendPosition = Dock.Bottom; 
     
                SeriesMapping seriesMapping1 = new SeriesMapping(); 
                seriesMapping1.LegendLabel = "Abgerechnete Arbeitsstunden"
                seriesMapping1.SeriesDefinition = new BarSeriesDefinition(); 
                ItemMapping itemMapping1 = new ItemMapping(); 
                itemMapping1.DataPointMember = DataPointMember.YValue; 
                itemMapping1.FieldName = "WorkedHours"
                ItemMapping itemMapping2 = new ItemMapping(); 
                itemMapping2.DataPointMember = DataPointMember.XCategory; 
                itemMapping2.FieldName = "ShortName"
                seriesMapping1.ItemMappings.Add(itemMapping1); 
                seriesMapping1.ItemMappings.Add(itemMapping2); 
                m_RadChart.SeriesMappings.Add(seriesMapping1);                   
                             
                SeriesMapping seriesMapping2= new SeriesMapping(); 
                seriesMapping2.LegendLabel = "Bezahlte Arbeitsstunden"
                seriesMapping2.SeriesDefinition = new BarSeriesDefinition(); 
                ItemMapping itemMapping3 = new ItemMapping(); 
                itemMapping3.DataPointMember = DataPointMember.YValue; 
                itemMapping3.FieldName = "PaidHours"
                ItemMapping itemMapping4 = new ItemMapping(); 
                itemMapping4.DataPointMember = DataPointMember.XCategory; 
                itemMapping4.FieldName = "ShortName"
                seriesMapping2.ItemMappings.Add(itemMapping3); 
                seriesMapping2.ItemMappings.Add(itemMapping4); 
                m_RadChart.SeriesMappings.Add(seriesMapping2); 
                 
                m_CB_Year.SelectedItem = DateTime.Now.Year; 
                m_CB_Month.SelectedIndex = 0; 
                m_CB_Year.SelectionChanged +=new SelectionChangedEventHandler(TimeSpanModified); 
                m_CB_Month.SelectionChanged += new SelectionChangedEventHandler(TimeSpanModified); 
     
                m_RadChart.DefaultView.ChartArea.ItemToolTipOpening += this.ChartItemToolTipOpening; 
     
                UpdateData(); 
            } 
     
     
     
     
     
            private void ChartItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs args) 
            { 
                RadChart chart = new RadChart(); 
                chart.Height = 200; 
                chart.Width = 300; 
     
                chart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed; 
                chart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside; 
                string axisItemLabel = m_RadChart.DefaultView.ChartArea.AxisX.TickPoints[args.ItemIndex].Label; 
                chart.DefaultView.ChartTitle.Content = string.Format("Quarterly Preview: {0}", axisItemLabel); 
     
                chart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "C"
     
                DataSeries series = new DataSeries(); 
                series.Definition = new LineSeriesDefinition(); 
                series.Definition.ShowItemLabels = false
                //SeriesExtensions.FillWithSampleData(series, 4, (int)args.DataPoint.YValue); 
     
                string[] quarters = new string[] { "Q1""Q2""Q3""Q4" }; 
     
                for (int i = 0; i < chart.DefaultView.ChartArea.AxisX.TickPoints.Count; i++) 
                    series[i].XCategory = quarters[i]; 
     
                //for (int i = 0; i < series.Count; i++) 
                //    quarterlyRevenues[i] = series[i].YValue; 
     
                chart.DefaultView.ChartArea.DataSeries.Add(series); 
     
                tooltip.Content = chart; 
            } 
     
     
     
     
     
            private void UpdateData() 
            { 
                int selectedYear = (int)m_CB_Year.SelectedItem; 
                string selectedMonthString = (string)m_CB_Month.SelectedItem; 
                bool wholeYear = false
                int selectedMonth = 0; 
                if (selectedMonthString == "Komplettes Jahr"
                    wholeYear = true
                else 
                    selectedMonth = DateTime.ParseExact(selectedMonthString, "MMMM", CultureInfo.CurrentCulture).Month; 
     
                DateTime startTime; 
                DateTime endTime; 
                if (wholeYear) 
                { 
                    startTime = new DateTime(selectedYear, 1, 1); 
                    endTime = new DateTime(selectedYear + 1, 1, 1); 
                } 
                else 
                { 
                    startTime = new DateTime(selectedYear, selectedMonth, 1); 
                    endTime = new DateTime(selectedYear, selectedMonth, 1).AddMonths(1); 
                } 
     
                List<ChartData> chartData = new List<ChartData>(); 
                foreach (Employee emp in m_Employees.Values) 
                { 
                    double workedHours = m_AppointmentScheduler.GetWorkedHours(startTime, endTime, emp); 
                    double paidHours = m_AppointmentScheduler.GetPaidHours(startTime, endTime, emp); 
                    chartData.Add(new ChartData(emp.FirstName, emp.LastName, workedHours, paidHours)); 
                } 
     
                m_RadChart.ItemsSource = chartData; 
            } 
     
            private void CheckBox_Checked(object sender, RoutedEventArgs e) 
            { 
                CheckBox sourceCheckbox = e.OriginalSource as CheckBox; 
                Queue<ChartFilterDescriptor> filtersToRemove = new Queue<ChartFilterDescriptor>(); 
     
                foreach (ChartFilterDescriptor descriptor in m_RadChart.FilterDescriptors) 
                { 
                    if (descriptor.Value.Equals(sourceCheckbox.Content)) 
                        filtersToRemove.Enqueue(descriptor); 
                } 
     
                foreach (ChartFilterDescriptor descriptor in filtersToRemove) 
                    m_RadChart.FilterDescriptors.Remove(descriptor); 
     
            } 
     
            private void CheckBox_Unchecked(object sender, RoutedEventArgs e) 
            { 
                CheckBox sourceCheckbox = e.OriginalSource as CheckBox; 
                m_RadChart.FilterDescriptors.Add(new ChartFilterDescriptor("FullName"typeof(string), FilterOperator.IsNotEqualTo, sourceCheckbox.Content)); 
            } 
     
            private void TimeSpanModified(object sender, SelectionChangedEventArgs e) 
            { 
                UpdateData(); 
            } 
        } 

    I am custom classes which are connected via SeriesMapping.

    Best regards,
    Markus Demmler
  2. Markus Demmler
    Markus Demmler avatar
    5 posts
    Member since:
    Mar 2010

    Posted 06 Apr 2010 Link to this post

    Comparing it with the provided examples, I found out that I am missing something like:
    series.Definition.ShowItemToolTips = true;

    But I don't know how I could use that as I am using SeriesMapping and not DataSeries directly.
    Any suggestions?

    Best regards,
    Markus Demmler
  3. UI for WPF is Visual Studio 2017 Ready
  4. Velin
    Admin
    Velin avatar
    391 posts

    Posted 07 Apr 2010 Link to this post

    Hello Markus Demmler,

    Here is an excerpt from the code you provided which I modified in order to enable tooltips in your scenario. You should apply the changes to all the SeriesMapping objects you have:
    SeriesMapping seriesMapping1 = new SeriesMapping();
    seriesMapping1.LegendLabel = "Abgerechnete Arbeitsstunden";
    seriesMapping1.SeriesDefinition = new BarSeriesDefinition(){ ShowItemToolTips = true};

    Greetings,
    Velin
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Markus Demmler
    Markus Demmler avatar
    5 posts
    Member since:
    Mar 2010

    Posted 07 Apr 2010 Link to this post

    Solved the problem.
    Thanks a lot for your help!

    Markus
  6. Anitha
    Anitha avatar
    33 posts
    Member since:
    Apr 2012

    Posted 03 Jul 2012 Link to this post

    If we are using  

     

    ShowItemToolTips

     

     

    ="True"

    the tooltip value is visible thorughout the line, I want to show the value as tooltip only at the data point not on the total line.

     


     

     

     

     

     

    Thanks in Advance

     

Back to Top
UI for WPF is Visual Studio 2017 Ready