Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with WPF Chart inside ListBox
    text
    copied!<p>I have been using DataVisualization.Charting.Chart to produce few charts. Everything works very well, until when I put the same inside a DataTemplate of a ListBox. </p> <p>Inside the ListBox, the Chart data shows up properly, but the Legends are not showing.</p> <p>I have been using Normal LineSeries chart. Here is the code : </p> <pre><code>&lt;ListBox Style="{DynamicResource listBasic}" FontSize="12" FontWeight="Normal" ItemsSource="{Binding PsychrometricLogs}"&gt; &lt;ListBox.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.ContainerStyle&gt; &lt;Style TargetType="{x:Type GroupItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Expander Header="{Binding Name}" FontFamily="Calibri" FontSize="18" Foreground="{DynamicResource defForegroundBrush}" IsExpanded="True"&gt; &lt;ItemsPresenter /&gt; &lt;/Expander&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/GroupStyle.ContainerStyle&gt; &lt;/GroupStyle&gt; &lt;/ListBox.GroupStyle&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Border CornerRadius="5" Margin="2,5,2,5" Opacity=".3" Background="#000000" /&gt; &lt;DockPanel&gt; &lt;chart:Chart Title="{Binding DisplayName}" FontSize="14" DockPanel.Dock="Top" LegendTitle="Legends" Margin="20,15,20,5" Foreground="#000000" DataContext="{Binding Logs}"&gt; &lt;chart:LineSeries Title="Temperature" AnimationSequence="FirstToLast" IndependentValueBinding="{Binding TimeStamp}" DependentValueBinding="{Binding Temparature}" ItemsSource="{Binding}" /&gt; &lt;chart:LineSeries Title="Relative Humidity" AnimationSequence="FirstToLast" IndependentValueBinding="{Binding TimeStamp}" DependentValueBinding="{Binding RelativeHumidity}" ItemsSource="{Binding}" /&gt; &lt;chart:LineSeries Title="Grains Per Pound" AnimationSequence="FirstToLast" IndependentValueBinding="{Binding TimeStamp}" DependentValueBinding="{Binding GrainsPerPound}" ItemsSource="{Binding}" /&gt; &lt;chart:LineSeries Title="Grains Depression" AnimationSequence="FirstToLast" IndependentValueBinding="{Binding TimeStamp}" DependentValueBinding="{Binding GrainsDepression}" ItemsSource="{Binding}" /&gt; &lt;/chart:Chart&gt; &lt;ListView ItemsSource="{Binding Logs}" DockPanel.Dock="Top" Margin="5,0,5,5" Padding="0"&gt; &lt;ListView.View&gt; &lt;GridView AllowsColumnReorder="True"&gt; &lt;GridViewColumn Header="Time Stamp" DisplayMemberBinding="{Binding TimeStamp}" /&gt; &lt;GridViewColumn Header="Temperature" DisplayMemberBinding="{Binding Temparature}" /&gt; &lt;GridViewColumn Header="RH" DisplayMemberBinding="{Binding RelativeHumidity}" /&gt; &lt;GridViewColumn Header="GPP" DisplayMemberBinding="{Binding GrainsPerPound}" /&gt; &lt;GridViewColumn Header="GD" DisplayMemberBinding="{Binding GrainsDepression}" /&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;/DockPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>You can see, I have placed one ListView and a Chart. The ListView shows data properly as well as the chart. But the Legends does not show up. </p> <p>I have already tried to put the same chart outside the ListBox and it shows up Legends correctly but not inside the DataTemplate. </p> <p>It would be helpful if somebody tell me where I am wrong in this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload