2016-07-12 3 views
2

Я использую библиотеку LiveChart, и у меня есть проблема с отображением диаграмм. Действительно, в моем окне я хочу много диаграмм со многими типами, поэтому я использую DataTemplateSelector, ссылку на класс для каждого типа диаграммы. Но, когда диаграмма появляется, на ней нет данных. Я попытался добавить DataContext="{Binding}" в объявление моего «Графа столбцов», но безуспешно.CartesianChart (Live-Charts) не работает с DataTemplate

Вот выдержка из моего кода:

ResultView.xaml

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> 
    <FrameworkElement.Resources> 

     <DataTemplate x:Key="graphEmptyTemlpate"> 
      <StackPanel Width="Auto" Height="60" Orientation="Horizontal" MaxWidth="700"> 
       <TextBlock Text="{Binding name}" VerticalAlignment="Center" TextAlignment="Center" FontSize="20" Margin="0,0,0,0" Foreground="#FF006B93"/> 
      </StackPanel> 
     </DataTemplate> 

     <DataTemplate x:Key="columnTemplate"> 
      <StackPanel Background="#FFBFBFBF"> 
       <TextBlock Text="{Binding title}"/> 
       <TextBlock Text="{Binding subTitle}"/> 
       <lvc:CartesianChart Width="400" Height="400" Series="{Binding listSeries}"> 
       </lvc:CartesianChart> 
      </StackPanel> 
     </DataTemplate> 

     <local:GraphTemplateSelector 
     ColumnTemplate="{StaticResource columnTemplate}" 
     GraphEmptyTemplate="{StaticResource graphEmptyTemlpate}" 
     x:Key="graphTemplateSelector" /> 

    </FrameworkElement.Resources> 
    <StackPanel Orientation="Horizontal" > 
     <ItemsControl ItemsSource="{Binding Results}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Expander Header="{Binding Title}" 
           IsExpanded="True" 
           Margin="10 10 10 10" 
           FontSize="20" 
           Foreground="White"> 
         <ItemsControl ItemsSource="{Binding Items}" 
             ItemTemplateSelector="{DynamicResource graphTemplateSelector}"> 
          <ItemsControl.ItemsPanel> 
           <ItemsPanelTemplate> 
            <WrapPanel Margin="10 10 10 10" Orientation="Vertical"/> 
           </ItemsPanelTemplate> 
          </ItemsControl.ItemsPanel> 
         </ItemsControl> 
        </Expander> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </StackPanel> 
</ScrollViewer> 

конструктор моего класса ViewModel в ResultViewModel.cs В XAML, результаты соответствуют результатам в C#, Items соответствует к RpAgitation.Items в C#

public ResultsViewModel() 
{ 
    instance = this; 
    this.Results = new ObservableCollection<ResultParts>(); 
    this.RpAgitation = new ResultParts("Results of the Agitation part"); 

    ColumnGraph gr = new ColumnGraph(); 
    RpAgitation.Items.Add(gr); 

    this.Results.Add(_rpAgitation); 

} 

и finnaly в ColumnGraph.cs

public class ColumnGraph : IGraph 
{ 
    public SeriesCollection listSeries { get; set; } 

    public ColumnGraph() 
    { 
     listSeries = new SeriesCollection 
     { 
      new LineSeries 
      { 
       Title = "Series 1", 
       Values = new ChartValues<double> { 4,7,8,9,5,4,2} 
      } 
     }; 
    } 
} 

Спасибо за вашу помощь,

+0

Спасибо за открытие этого вопроса в репо, я исправлю это как можно скорее –

+0

это уже исправлено, так как 0.7.7 версия –

+0

Большое спасибо! – bobbinch

ответ

0

В настоящее время SeriesCollection класс не элемент WPF UiFramework, я действительно не хотела, но я предполагаю, что нам нужно сделать, это т, чтобы избежать этой проблемы.

Я не уверен, что это ошибка с WPF, или просто мы делаем что-то неправильно.

любые пути, я буду исследовать дальше, пока альтернатива попробовать этот синтаксис:

DataSource = new List<ChartValues<double>> 
     { 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)}, 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)}, 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)} 
     }; 

     DataContext = this; 

And The XAML

<ItemsControl ItemsSource="{Binding DataSource}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <lvc:CartesianChart Height="400"> 
         <lvc:CartesianChart.Series> 
          <lvc:LineSeries Values="{Binding}"></lvc:LineSeries> 
         </lvc:CartesianChart.Series> 
        </lvc:CartesianChart> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
Смежные вопросы