?
Solved

Silverlight Sparkline chart not showing data easy one

Posted on 2010-11-11
6
Medium Priority
?
1,318 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
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!

 
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 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Screencast - Getting to Know the Pipeline

807 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