有非常基本的SilverLight LineSeries图表的问题

时间:2010-11-03 16:47:38

标签: c# asp.net silverlight .net-3.5 silverlight-4.0

最近几天我一直在试图找出SilverLight 4 LineSeries图,因为一些奇怪的原因显示图表但是没有显示该行。我很确定我的错误是非常基本的,但我一直在努力查明这个问题。

Bellow是我遇到问题的代码。

<toolkit:Chart HorizontalAlignment="Left" x:Name="chartLine" Margin="31,35,0,0" Title="Chart for test" VerticalAlignment="Top" Height="233" Width="309">
        <toolkit:LineSeries IsSelectionEnabled="True" HorizontalAlignment="Left" DependentValuePath="Y" IndependentValuePath="X" Margin="195,49,0,0" Name="lineSeries1" VerticalAlignment="Top" Height="78" Width="130">
                <toolkit:LineSeries.ItemsSource>          
                    <PointCollection>
                        <Point>1,10</Point>
                        <Point>2,20</Point>
                        <Point>3,30</Point>
                        <Point>4,40</Point>
                    </PointCollection>        
            </toolkit:LineSeries.ItemsSource>           

        </toolkit:LineSeries>           
        </toolkit:Chart>

如果有人能指出我在Silverlight上使用可滚动图形的代码示例,我也会感到沮丧。

提前谢谢。

1 个答案:

答案 0 :(得分:3)

这是更正后的XAML。您的问题是您在LineSeries中设置的Horizo​​ntalAlignment / VerticalAlignment / Margin / Width / Height。删除这些可以解决问题。

这是完整的XAML,它显示了正确放置线条的图表。

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
    <toolkit:Chart HorizontalAlignment="Left" x:Name="chartLine" Margin="31,35,0,0" Title="Chart for test" VerticalAlignment="Top" Height="233" Width="309">
      <toolkit:LineSeries IsSelectionEnabled="True" DependentValuePath="Y" IndependentValuePath="X" Name="lineSeries1">
        <toolkit:LineSeries.ItemsSource>
          <PointCollection>
            <Point>1,10</Point>
            <Point>2,20</Point>
            <Point>3,30</Point>
            <Point>4,40</Point>
          </PointCollection>
        </toolkit:LineSeries.ItemsSource>
      </toolkit:LineSeries>
    </toolkit:Chart>
  </Grid>
</UserControl>