?
Solved

Silverlight Sparkline chart not showing data easy one

Posted on 2010-11-11
6
Medium Priority
?
1,308 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 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