LineSeries Title in DataTemplate

Oct 25, 2010 at 8:21 PM

Hi,

I am using an ItemsControl to present a collection I have stored in my view model.  The DataTemplate defined for this collection involves creating some charts that use LineSeries.  The problem I'm having is that the label in the legend isn't getting copied over from the "Title" attribute just shows Series 1, Series 2, etc..  I was wondering if anyone else has run into this problem and if you found a solution for it.  Thanks in advance for your time

nssjp

Oct 26, 2010 at 5:25 PM
Edited Oct 26, 2010 at 8:07 PM

Wrote up a simple example of what I'm seeing, can someone see where I'm doing wrong here?

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
        xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="Window1" Height="300" Width="300">
    <Grid>
      <Grid.Resources>
        <local:SalesDataCollection x:Key="SalesDataCollection"/>

      <DataTemplate DataType="{x:Type local:SalesDataCollectionViewModel}">
        <StackPanel>
          <Charting:Chart Title="Data Template" Width="400" Height="320" Margin="5,0,0,0" Background="White" DataContext="{Binding SalesDataCollection}">
            <Charting:LineSeries Title="West Store" ItemsSource="{Binding}" IndependentValuePath="Animal" DependentValuePath="WestStoreQuantity"/>
            <Charting:LineSeries Title="East Store" ItemsSource="{Binding}" IndependentValuePath="Animal" DependentValuePath="EastStoreQuantity"/>
          </Charting:Chart>
        </StackPanel>
      </DataTemplate>

    </Grid.Resources>

    <ScrollViewer HorizontalScrollBarVisibility="Auto">
      <StackPanel>
        <Charting:Chart Title="No Data Template" Width="400" Height="320" Margin="5,0,0,0" Background="White" DataContext="{StaticResource SalesDataCollection}">
          <Charting:LineSeries Title="West Store" ItemsSource="{Binding}" IndependentValuePath="Animal" DependentValuePath="WestStoreQuantity"/>
          <Charting:LineSeries Title="East Store" ItemsSource="{Binding}" IndependentValuePath="Animal" DependentValuePath="EastStoreQuantity"/>
        </Charting:Chart>
        <ContentPresenter Content="{Binding SalesDataCollectionViewModel}"/>
      </StackPanel>
    </ScrollViewer>
     
    </Grid>
</Window>

using System.Windows;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            m_SalesDataCollectionViewModel = new SalesDataCollectionViewModel();
            InitializeComponent();
            DataContext = this;
        }

        private SalesDataCollectionViewModel m_SalesDataCollectionViewModel;

        public SalesDataCollectionViewModel SalesDataCollectionViewModel
        {
            get
            {
                return m_SalesDataCollectionViewModel;
            }
            set
            {
                m_SalesDataCollectionViewModel = value;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace WpfApplication1
{
    public class SalesData
    {
        public string Animal { get; set; }
        public int WestStoreQuantity { get; set; }
        public int EastStoreQuantity { get; set; }
    }
   
    public class SalesDataCollection : Collection<SalesData>
    {
        public SalesDataCollection()
        {
            Add(new SalesData { Animal = "Dogs", WestStoreQuantity = 5, EastStoreQuantity = 7 });
            Add(new SalesData { Animal = "Cats", WestStoreQuantity = 5, EastStoreQuantity = 6 });
            Add(new SalesData { Animal = "Birds", WestStoreQuantity = 3, EastStoreQuantity = 8 });
            Add(new SalesData { Animal = "Fish", WestStoreQuantity = 6, EastStoreQuantity = 9 });
        }
    }

    public class SalesDataCollectionViewModel
    {
        public SalesDataCollectionViewModel()
        {
            SalesDataCollection = new SalesDataCollection();
        }

        public SalesDataCollection SalesDataCollection { get; set; }
    }
}

Thanks in advance for your time

Oct 27, 2010 at 4:32 PM

From the debugging I've been able to do it seems like problem is the LineSeries not taking the title attribute on apply template, but I can't see why

Dec 14, 2010 at 4:51 PM

I'm having this issue too :-(.

Did you get anywhere with this?

Dec 30, 2010 at 2:49 PM

Same issue to me too. 

No one with a solution, this is weird..... :(