2014-10-02 3 views
2

저는 WPF 응용 프로그램에서 RadChart 컨트롤을 사용하고 있습니다. 나는 ItemToolTipFormat 및 DataPointMember = "툴팁"기능에 대해 잘 알고 있어요,하지만 난 다음이 가능 궁금 :RadChart - X 축 자체에 대한 툴팁 - Telerik

내가 데모에 대한 이미지를 첨부했습니다 :

enter image description here

그것이 가능 x 축 카테고리에 마우스 커서를 올려 놓으면 도구 설명이 표시됩니다 : 예 : 첨부 된 이미지에서 마우스 커서로 May (또는 Sep 또는 Nov 등)이라는 단어를 가리키면, 나는 툴팁을 얻을 것이다.

위에서 언급 한 기능이 어떻게되는지, 다이어그램 자체에 대한 툴팁이 표시되지만, 언급 한 바와 같이 x 축의 카테고리 자체에 대한 툴팁이 필요합니다 (달의 단어를 마우스로 가리키면 영상).

도움을 주셔서 감사합니다.

답변

2

좋은 질문입니다. 내가 아는 한 논란이 많은 구현을 사용하지 않고도 해당 레이블에 대한 툴팁을 설정할 수 없습니다. 솔루션이 있지만 오히려 해킹이며 고정 축 데이터 만 지원합니다. 바인딩을 지원하지 않습니다 (툴팁 내용을 ItemMapping 요소를 통해 전달하는 것이 발견되지 않았습니다).

상기 용액은 3 부; ResourceDictionary, ConverterRadChart 컨트롤.

ResourceDictionary (같은 DLL의 자원 폴더에있는 "ToolTipResources.xaml"명명 된) 도구 설명의 내용이 포함되어

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <StackPanel 
     x:Key="Jan"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Jan" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In January" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Feb"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Feb" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In February" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Mar"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Mar" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In March" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Apr"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Apr" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In April" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="May"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="May" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In May" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Jun"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Jun" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In June" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Jul"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Jul" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In July" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Aug"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Aug" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In August" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Sep"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Sep" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In September" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Oct"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Oct" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In October" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Nov"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Nov" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In November" /> 
    </StackPanel> 
    <StackPanel 
     x:Key="Dec"> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="Dec" 
      FontWeight="Bold" /> 
     <TextBlock 
      HorizontalAlignment="Left" 
      Text="In December" /> 
    </StackPanel> 
</ResourceDictionary> 

관련이있는 Converter 링크 레이블 이름을 도구 설명 내용 다음 RadChart 제어

/// <summary> 
/// Converts chart label names into associated ToolTip content. 
/// </summary> 
[ValueConversion(typeof(string), typeof(object))] 
public class MonthToToolTipConverter : IValueConverter 
{ 
    private static string _assemblyName; 

    static MonthToToolTipConverter() 
    { 
     _assemblyName = Assembly.GetExecutingAssembly().FullName; 
    } 

    /// <summary> 
    /// Converts a value. 
    /// </summary> 
    /// <param name="value">The value produced by the binding source.</param> 
    /// <param name="targetType">The type of the binding target property.</param> 
    /// <param name="parameter">The converter parameter to use.</param> 
    /// <param name="culture">The culture to use in the converter.</param> 
    /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> 
    public object Convert(object value, Type targetType, 
     object parameter, CultureInfo culture) 
    { 
     object result = null; 
     var labelName = value as string; 
     if (labelName != null) 
     { 
      var toolTipResourcesDictionary = new ResourceDictionary(); 

      toolTipResourcesDictionary.Source = new Uri(String.Format("pack://application:,,,/{0};component/Resources/ToolTipResources.xaml", _assemblyName), UriKind.Absolute); 
      result = toolTipResourcesDictionary[labelName]; 
     } 
     return result; 
    } 

    /// <summary> 
    /// Converts a value. 
    /// </summary> 
    /// <param name="value">The value that is produced by the binding target.</param> 
    /// <param name="targetType">The type to convert to.</param> 
    /// <param name="parameter">The converter parameter to use.</param> 
    /// <param name="culture">The culture to use in the converter.</param> 
    /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> 
    public object ConvertBack(object value, Type targetType, 
     object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

추가 :

합니다 ( Telerik Documentation에서 예)
<telerikCharting:ChartArea.AxisX> 
    <telerikCharting:AxisX> 
     <telerikCharting:AxisX.AxisStyles> 
      <telerikCharting:AxisStyles> 
       <telerikCharting:AxisStyles.ItemLabelStyle> 
        <Style 
         TargetType="{x:Type TextBlock}"> 
         <Setter 
          Property="ToolTip" 
          Value="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource MonthToToolTipConverter}}" /> 
        </Style> 
       </telerikCharting:AxisStyles.ItemLabelStyle> 
      </telerikCharting:AxisStyles> 
     </telerikCharting:AxisX.AxisStyles> 
    </telerikCharting:AxisX> 
</telerikCharting:ChartArea.AxisX> 

전체 RadChart보기 :

<Window 
    x:Class="YourChartProject.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    xmlns:telerikCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting" 
    xmlns:local="clr-namespace:YourChartProject" 
    Title="MainWindow" 
    Height="350" 
    Width="525"> 
    <Window.Resources> 
     <local:MonthToToolTipConverter 
      x:Key="MonthToToolTipConverter" /> 
    </Window.Resources> 
    <Grid> 
     <telerik:RadChart 
      VerticalAlignment="Top"> 
      <telerik:RadChart.DefaultView> 
       <telerikCharting:ChartDefaultView> 
        <telerikCharting:ChartDefaultView.ChartTitle> 
         <telerikCharting:ChartTitle 
          Content="Year 2009" 
          HorizontalAlignment="Center" /> 
        </telerikCharting:ChartDefaultView.ChartTitle> 
        <telerikCharting:ChartDefaultView.ChartLegend> 
         <telerikCharting:ChartLegend 
          x:Name="chartLegend" 
          UseAutoGeneratedItems="True" /> 
        </telerikCharting:ChartDefaultView.ChartLegend> 
        <telerikCharting:ChartDefaultView.ChartArea> 
         <telerikCharting:ChartArea 
          LegendName="chartLegend"> 
          <telerikCharting:ChartArea.AxisX> 
           <telerikCharting:AxisX 
            LayoutMode="Between" 
            Title="Month"> 
            <telerikCharting:AxisX.AxisStyles> 
             <telerikCharting:AxisStyles> 
              <telerikCharting:AxisStyles.ItemLabelStyle> 
               <Style 
                TargetType="{x:Type TextBlock}"> 
                <Setter 
                 Property="ToolTip" 
                 Value="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource MonthToToolTipConverter}}" /> 
               </Style> 
              </telerikCharting:AxisStyles.ItemLabelStyle> 
             </telerikCharting:AxisStyles> 
            </telerikCharting:AxisX.AxisStyles> 
           </telerikCharting:AxisX> 
          </telerikCharting:ChartArea.AxisX> 
          <telerikCharting:ChartArea.DataSeries> 
           <!-- Line Chart --> 
           <telerikCharting:DataSeries 
            LegendLabel="Turnover"> 
            <telerikCharting:DataSeries.Definition> 
             <telerikCharting:LineSeriesDefinition></telerikCharting:LineSeriesDefinition> 
            </telerikCharting:DataSeries.Definition> 
            <telerikCharting:DataPoint 
             YValue="154" 
             XCategory="Jan" /> 
            <telerikCharting:DataPoint 
             YValue="138" 
             XCategory="Feb" /> 
            <telerikCharting:DataPoint 
             YValue="143" 
             XCategory="Mar" /> 
            <telerikCharting:DataPoint 
             YValue="120" 
             XCategory="Apr" /> 
            <telerikCharting:DataPoint 
             YValue="135" 
             XCategory="May" /> 
            <telerikCharting:DataPoint 
             YValue="125" 
             XCategory="Jun" /> 
            <telerikCharting:DataPoint 
             YValue="179" 
             XCategory="Jul" /> 
            <telerikCharting:DataPoint 
             YValue="170" 
             XCategory="Aug" /> 
            <telerikCharting:DataPoint 
             YValue="198" 
             XCategory="Sep" /> 
            <telerikCharting:DataPoint 
             YValue="187" 
             XCategory="Oct" /> 
            <telerikCharting:DataPoint 
             YValue="193" 
             XCategory="Nov" /> 
            <telerikCharting:DataPoint 
             YValue="176" 
             XCategory="Dec" /> 
           </telerikCharting:DataSeries> 
           <!-- Bar Chart --> 
           <telerikCharting:DataSeries 
            LegendLabel="Expenses"> 
            <telerikCharting:DataSeries.Definition> 
             <telerikCharting:BarSeriesDefinition></telerikCharting:BarSeriesDefinition> 
            </telerikCharting:DataSeries.Definition> 
            <telerikCharting:DataPoint 
             YValue="45" 
             XCategory="Jan" /> 
            <telerikCharting:DataPoint 
             YValue="48" 
             XCategory="Feb" /> 
            <telerikCharting:DataPoint 
             YValue="53" 
             XCategory="Mar" /> 
            <telerikCharting:DataPoint 
             YValue="41" 
             XCategory="Apr" /> 
            <telerikCharting:DataPoint 
             YValue="32" 
             XCategory="May" /> 
            <telerikCharting:DataPoint 
             YValue="28" 
             XCategory="Jun" /> 
            <telerikCharting:DataPoint 
             YValue="63" 
             XCategory="Jul" /> 
            <telerikCharting:DataPoint 
             YValue="74" 
             XCategory="Aug" /> 
            <telerikCharting:DataPoint 
             YValue="77" 
             XCategory="Sep" /> 
            <telerikCharting:DataPoint 
             YValue="85" 
             XCategory="Oct" /> 
            <telerikCharting:DataPoint 
             YValue="89" 
             XCategory="Nov" /> 
            <telerikCharting:DataPoint 
             YValue="80" 
             XCategory="Dec" /> 
           </telerikCharting:DataSeries> 
          </telerikCharting:ChartArea.DataSeries> 
         </telerikCharting:ChartArea> 
        </telerikCharting:ChartDefaultView.ChartArea> 
       </telerikCharting:ChartDefaultView> 
      </telerik:RadChart.DefaultView> 
     </telerik:RadChart> 
    </Grid> 
</Window> 
+0

대단히 감사합니다! AxisStyles.ItemLabelStyle을 사용하여 트릭을 만들었습니다. – DimaK

관련 문제