Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
StackedBarSeries and tooltip
posted

Hi

I create my XamDataChart with one NumericXAxis and CategoryYAxis.

I create StackedBarSeries with GroupBy item source with AutoGenerateSeries = true.

Detail description here http://www.infragistics.com/community/forums/t/73787.aspx

I need now create toolTip for my series and segment. How i do it?

Binding like 

<DataTemplate x:Key="ToolTipTemplate">
<StackPanel>
<TextBlock Text="{Binding Item.Key}" />
<TextBlock Text="{Binding Item.Hodnota}" />
</StackPanel>
</DataTemplate>

 not working.

  • 435
    Verified Answer
    posted

    Hi

    I found solution thrue convertor.

    I create datatemplate for ToolTip

    <local:SeriesConverter x:Key="seriesConverter" />
    <DataTemplate x:Key="ToolTipTemplate">
    <StackPanel>
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Název: " FontWeight="Bold"/>
    <TextBlock Text="{Binding Path=., Converter={StaticResource seriesConverter}, ConverterParameter=FragmentNazev}" />
    </StackPanel>
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Období: " FontWeight="Bold"/>
    <TextBlock Text="{Binding Path=., Converter={StaticResource seriesConverter}, ConverterParameter=Datum}" />
    </StackPanel>
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Hodnota: " FontWeight="Bold" />
    <TextBlock Text="{Binding Path=., Converter={StaticResource seriesConverter}, ConverterParameter=Hodnota, StringFormat=F2}" />
    </StackPanel>
    </StackPanel>
    </DataTemplate>

    in code a write:

    StackedBarSeries series2 = new StackedBarSeries();
    //udalost kde pregeneruju titulek ktery se generuje blbe
    series2.SeriesCreated += series2_SeriesCreated;
    series2.Legend = this.xmLegend;
    series2.XAxis = xAxis;
    series2.YAxis = yAxis;
    series2.AutoGenerateSeries = true;

    //tooltip
    var toolTipTemplate = this.DataChart.Resources["ToolTipTemplate"] as DataTemplate;
    if (toolTipTemplate != null)
    {
    var toolTip = new ContentControl();
    toolTip.ContentTemplate = toolTipTemplate;
    Binding b2 = new Binding(".");
    toolTip.SetBinding(ContentControl.ContentProperty, b2);
    series2.ToolTip = toolTip;
    }
    series2.ItemsSource = gb;

    this.DataChart.Series.Add(series2);

    And code for convertor is:

    public class SeriesConverter : IValueConverter
    {
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
    Infragistics.Controls.Charts.DataContext dc = value as Infragistics.Controls.Charts.DataContext;
    if (dc != null)
    {
    Infragistics.Controls.Charts.AnchoredCategorySeries cs = dc.Series as Infragistics.Controls.Charts.AnchoredCategorySeries;
    string klic = cs.ValueMemberPath.Replace("_Hodnota", string.Empty);
    klic = klic + "_" + parameter.ToString();
    Binding b = new Binding();
    b.Path = new PropertyPath(klic);
    b.Source = dc.Item;
    FrameworkElement fe = new FrameworkElement();
    fe.SetBinding(FrameworkElement.TagProperty, b);
    fe.DataContext = dc.Item;
    return fe.Tag;
    }
    else
    {
    return null;
    }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
    return null;
    }
    }