Solved

Silverlight Sparkline chart not showing data easy one

Posted on 2010-11-11
6
1,297 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
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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