none
[求助]关于Silverlight 3 Toolkit中的Chart的问题 RRS feed

  • 问题

  • 由于要做图表,所以使用了Silverlight 3 Toolkit
    图形是柱状图

    XAML

    <UserControl
    
     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" 
    
     mc:Ignorable="d" xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Code.Jxc.Charts.MainPage"
    
     d:DesignWidth="951" d:DesignHeight="176">
    
     <Grid x:Name="LayoutRoot" Width="951" Height="176">
    
      <Grid.RowDefinitions >
    
       <RowDefinition Height="176"></RowDefinition>
    
      </Grid.RowDefinitions>
    
      <Grid.ColumnDefinitions>
    
       <ColumnDefinition Width="951"></ColumnDefinition>
    
      </Grid.ColumnDefinitions>
    
      <charting:Chart Name="SxdcChart" Width="951" Height="176" Grid.Column="0" Grid.Row="0">
    
      </charting:Chart>
    
     </Grid>
    
    </UserControl>
    
    
    
    
     C# 
    public MainPage()
      {
       InitializeComponent();
       //jcc.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(jcc_GetDataCompleted);//注册回调函数
        //jcc.GetDataAsync();//获取Web服务的数据
        this.SxdcChart.Axes.Add(new LinearAxis { Orientation = AxisOrientation.Y, Maximum = 700, Minimum = 0 });
       this.SxdcChart.Axes.Add(new CategoryAxis { Orientation = AxisOrientation.X });
       ColumnSeries cs = new ColumnSeries { Title = "Se1" };
       cs.IndependentValuePath = "Num";
       cs.DependentValuePath = "Value";
       this.SxdcChart.Series.Add(cs);
       cs.ItemsSource = new List<JxcChartData> 
       	{
      	new JxcChartData{ Num = "x1f" , Value = 201},
       	new JxcChartData{ Num = "x2f" , Value = 201}
    	};
     }
    
     /// <summary>
     /// 用于封装柱状图的数据对象
     /// </summary>
     class JxcChartData
     {
      /// <summary>
      /// 数据库的编号
      /// </summary>
      public string Num { get; set; }
    
      /// <summary>
      /// 编号对应的值
      /// </summary>
      public double Value { get; set; }
    
     }
    
    
    在C#代码中 SxdcChart 就是图表控件

    编译运行之后...始终是以下错误
    网页错误详细信息

    用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
    时间戳: Wed, 11 Aug 2010 05:32:04 UTC


    消息: Unhandled Error in Silverlight Application 未将对象引用设置到对象的实例。 位于 System.Windows.Controls.DataVisualization.Charting.ColumnSeries.<>c__DisplayClass8.<GetAxes>b__4()
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes(DataPoint firstDataPoint, Func`2 independentAxisPredicate, Func`1 independentAxisFactory, Func`2 dependentAxisPredicate, Func`1 dependentAxisFactory)
      位于 System.Windows.Controls.DataVisualization.Charting.ColumnSeries.GetAxes(DataPoint firstDataPoint)
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes()
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints)
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSingleSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints)
      位于 System.Windows.Controls.DataVisualization.Charting.ColumnBarBaseSeries`1.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints)
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeries.LoadDataPoints(IEnumerable newItems, IEnumerable oldItems)
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeries.Refresh()
      位于 System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnSizeChanged(Object sender, SizeChangedEventArgs e)
      位于 System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e)
      位于 MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)
    行: 1
    字符: 1
    代码: 0
    URI: http://localhost:3141/Code.Jxc.ChartsTestPage.html



    求教....
    另外:
    我在网上搜索了相关的教程。
    为什么有的命名空间的名称是:MicroSoft.Windows.Controls.DataVisualization.Charting
    而我的是:System.Windows.Controls.DataVisualization.Charting

    ?
    2010年8月11日 7:55

答案

全部回复