Solved

Silverlight Sparkline chart not showing data easy one

Posted on 2010-11-11
6
1,300 Views
Last Modified: 2013-12-17
Hello I am very new to sliverlight. I want to make a simple sparkline chart.

Here is the XAML.

<Grid Margin="0,0,0,0" Height="32" Width="78">
        <toolkit:Chart Width="75" Height="28" Margin="0,0,0,0" Name="TotalChart">
            <toolkit:Chart.Series>
                <toolkit:LineSeries IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding TotalValue}">
                    <toolkit:LineSeries.DataPointStyle>
                        <Style TargetType="Control">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </Style>
                    </toolkit:LineSeries.DataPointStyle>
                </toolkit:LineSeries>
            </toolkit:Chart.Series>
            <toolkit:Chart.Template>
                <ControlTemplate TargetType="toolkit:Chart">
                    <Grid x:Name="ChartArea">
                        <Grid x:Name="PlotArea" Background="LightGray">
                            <Grid x:Name="GridLinesContainer" />
                            <Grid x:Name="SeriesContainer" />
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </toolkit:Chart.Template>
            <toolkit:Chart.Axes>
                <toolkit:DateTimeAxis Orientation="X" MaxHeight="1" Opacity="0" Minimum="2010/01/01" Maximum="2010/02/08"/>
                <toolkit:LinearAxis Orientation="Y" MaxWidth="1" Opacity="0" Minimum="0" Maximum="1500"/>
            </toolkit:Chart.Axes>
        </toolkit:Chart>
    </Grid>

Here is the .CS

public partial class SmallLineGraph : UserControl {
      public SmallLineGraph() {
         InitializeComponent();

         List<DataStuff> oTest = new List<DataStuff>();
         oTest.Add(new DataStuff { Date = new DateTime(2010, 1, 1), TotalValue = 100 });
         oTest.Add(new DataStuff { Date = new DateTime(2010, 1, 2), TotalValue = 120 });
         oTest.Add(new DataStuff { Date = new DateTime(2010, 1, 3), TotalValue = 200 });
         oTest.Add(new DataStuff { Date = new DateTime(2010, 1, 4), TotalValue = 224 });
         oTest.Add(new DataStuff { Date = new DateTime(2010, 1, 5), TotalValue = 500 });
         oTest.Add(new DataStuff { Date = new DateTime(2010, 2, 1), TotalValue = 1000 });

         TotalChart.DataContext = oTest;
      }
   }

   public class DataStuff {
      public DateTime Date { get; set; }
      public decimal TotalValue { get; set; }
   }


right now the chart comes up empty. Any ideas?

thanks
CPG
0
Comment
Question by:copyPasteGhost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34118560
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 34121418
I'm really looking for a silverlight solution...

Thanks though.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 34127035
I can't see anything wrong with the code-behind - I slipped it into a WPF project and it populated  a ListBox without a hassle.
The only difference was that I set the DataContext for the whole Window:
    this.DataContext = oTest;

I'm not familiar with the Chart control - what is the idea of Opacity="0" on the axis (DateTimeAxis etc.)? Wouldn't that render the axis as transparent?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

by:copyPasteGhost
ID: 34137117
yes I really just want to see the lines.

Attached is what I'm trying to achieve.

CPG
SparklineSample.png
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 34137567
Does the chart appear if you remove the Collapsed setting on the DataPoint style?
<Setter Property="Visibility" Value="Collapsed"/>

If so there could be a clue here
From: http://blogs.msdn.com/b/delay/archive/2009/10/19/silverlight-and-wpf-data-visualization-classes-unsealed-silverlight-toolkit-october-2009-release-now-available.aspx
"One notable consequence of this change is that the Visibility of DataPoints is now controlled by the Series and will be set to Visible or Collapsed as necessary. Therefore, any customizations that directly set this property may no longer work, but there are other simple ways of achieving the same effect and this change is not expected to cause any difficulty. For example, the "Sparkline" demo of the samples project was affected by this change because it provided a custom DataPointStyle that set Visibility to Collapsed. The fix is not only trivial, but an improvement: change the Style to specify a null Template instead!"

I also found the attached sample from the page http://www.silverlight.net/content/samples/sl3/toolkitcontrolsamples/run/default.html
it seems to confirm that a change in the setting for DataPointStyle is needed:
                                        <Setter Property="Template" Value="{x:Null}"/>

<!-- Sparkline -->
            <Grid Style="{StaticResource WrapperStyle}">
                <StackPanel>
                    <ContentControl Content="Sparkline" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold"/>
                    <chartingToolkit:Chart Width="200" Height="50">
                        <chartingToolkit:Chart.Series>
                            <chartingToolkit:LineSeries
                                ItemsSource="{StaticResource WidgetPopularity}"
                                IndependentValueBinding="{Binding Date}"
                                DependentValueBinding="{Binding Percent}">
                                <chartingToolkit:LineSeries.DataPointStyle>
                                    <Style TargetType="Control">
                                        <Setter Property="Template" Value="{x:Null}"/>
                                    </Style>
                                </chartingToolkit:LineSeries.DataPointStyle>
                            </chartingToolkit:LineSeries>
                        </chartingToolkit:Chart.Series>
                        <chartingToolkit:Chart.Template>
                            <ControlTemplate TargetType="chartingToolkit:Chart">
                                <chartingPrimitivesToolkit:EdgePanel x:Name="ChartArea">
                                    <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
                                    <Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
                                </chartingPrimitivesToolkit:EdgePanel>
                            </ControlTemplate>
                        </chartingToolkit:Chart.Template>
                        <chartingToolkit:Chart.Axes>
                            <chartingToolkit:DateTimeAxis Orientation="X" MaxHeight="1" Opacity="0" Minimum="2008/07/07" Maximum="2008/09/08"/>
                            <chartingToolkit:LinearAxis Orientation="Y" MaxWidth="1" Opacity="0" Minimum="36" Maximum="55"/>
                        </chartingToolkit:Chart.Axes>
                    </chartingToolkit:Chart>
                </StackPanel>
            </Grid>

Open in new window

0
 
LVL 13

Author Closing Comment

by:copyPasteGhost
ID: 34146126
I found that same example and went with that. Thanks for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question