Solved

Silverlight Sparkline chart not showing data easy one

Posted on 2010-11-11
6
1,284 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now