Page tree
Skip to end of metadata
Go to start of metadata

第一步:将Chart3D添加到您的工程

在这一步,您将开始在Visual Studio中创建一个使用WPF和Silverlight版Chart3D 图表的应用程序。

  1. 在Visual Studio中创建一个新的WPF或Silverlight应用程序。
  2. 双击位于工具栏的C1Chart3D控件(位于在线文档'C1Chart3D Class'章节),以将其添加至您的窗体。XAML 标记将类似于下面的代码片段所示:

XAML - WPF

<Window x:Class="WFPChart3DQuickstart.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c1chart3d="http://schemas.componentone.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" >
<Grid>
<c1chart3d:C1Chart3D Height="150" HorizontalAlignment="Left"
Margin="10,10,0,0" Name="c1Chart3D1" VerticalAlignment="Top" Width="200">
<c1chart3d:GridDataSeries ZDataString="1 1 1,2 2 2,3 3 3" /> </c1chart3d:C1Chart3D>
</Grid>
</Window>

XAML - Silverlight

<UserControl xmlns:c1chart3d="http://schemas.componentone.com/winfx/2006/xaml" x:Class="MySilverlightApplication.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" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<c1chart3d:C1Chart3D Name="c1Chart3D1"/>
</Grid>
</UserControl>
在下一步中,您将添加自己的数据到图表中。

第二步:添加数据

WPF和Silverlight版Chart3D 支持数据值定义为一个二维数组的z值,其在第一个索引对应的X坐标,第二个索引值对
应Y坐标。Chart3D 最常见的用途之一就是绘制3D功能。让我们绘制一个函数定义如下: z(x,y) = x*x - y*y; 位于范围
-1 <= x <= 1 -1 <= y <= 1
要做到这一点,请遵循以下步骤:

  1. 在你的工程中选择视图|代码。
  2. 在页面顶部添加如下语句: C# - WPF

using C1.WPF.C1Chart3D;

C# - Silverlight using C1.Silverlight.Chart3D

  1. 添加以下代码用于定义数据: C#

public MainWindow()
{
InitializeComponent(); c1Chart3D1.Children.Clear();
// 创建 2D 数组 10x10 int xlen = 10, ylen = 10; var zdata = new double

[xlen, ylen];

double stepx = 2.0 / (xlen - 1); double stepy = 2.0 / (ylen - 1);
// 计算范围内的全部点
for (int ix = 0; ix < xlen; ix++) for (int iy = 0; iy < ylen; iy++)
{
double x = -1.0 + ix * stepx; // -1 <= x <= 1 double y = -1.0 + iy * stepy; // -1 <= x <= 1

zdata[ix, iy] = x * x - y * y;


}
// 创建数据系列 var ds = new GridDataSeries(); ds.Start = new Point(-1, -1); // 起始点x,y ds.Step = new Point(stepx, stepy); // 阶梯x,y ds.ZData = zdata; // z-values
// 添加系列至图表
c1Chart3D1.Children.Add(ds); }
在下一步中,您将改变图表的外观。


第三步:改变图表外观

在这一步中您将图表类型更改为SurfaceZone,设置图表底部的外观,旋转该图表,并改变其仰角。

  1. 在您的窗体中选中C1Chart3D (在线文档中位于'C1Chart3D Class' ),并单击查看|属性窗体。
  2. 通过点击ChartType(位于在线文档'ChartType 属性')属性旁边的下拉箭头以更改图表类型,并选择

SurfaceZone。

  1. 单击FloorAppearance (位于在线文档'FloorAppearance属性')属性,并选择ZoneContour。
  2. 在Elevation(位于在线文档'Elevation 属性')属性一栏,填写170。
  3. 设置Azimuth(位于在线文档'Azimuth 属性')属性的值为20。 XAML标记将类似于下面的代码所示:

XAML - WPF

<Window x:Class="WFPChart3DQuickstart.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"
xmlns:c1chart3d="http://schemas.componentone.com/xaml/c1chart">
<Grid>
<c1chart3d:C1Chart3D Height="150" HorizontalAlignment="Left"
Margin="10,10,0,0" Name="c1Chart3D1" VerticalAlignment="Top" Width="200"
ChartType="SurfaceZone" CeilAppearance="None" FloorAppearance="ZoneContour"
Elevation="170" Azimuth="20">
<c1chart3d:GridDataSeries ZDataString="1 1 1,2 2 2,3 3 3" />
</c1chart3d:C1Chart3D>
</Grid>
</Window>

XAML - Silverlight

<UserControl xmlns:c1chart3d="clr-
namespace:C1.Silverlight.Chart3D;assembly=C1.Silverlight.Chart3D" x:Class="SilverlightApplication12.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" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<c1chart3d:C1Chart3D Name="c1Chart3D1" ChartType="SurfaceZone"
FloorAppearance="ZoneContour" Elevation="170" Azimuth="20"/>
<c1chart3d:C1Chart3D />
</Grid>
</UserControl>
在下一步中,您将为图表添加一个图例。第四步:添加一个图例
在这一步中,您将为图表添加一个图例,仅需通过设置一个属性。

  1. 在您的窗体中选中C1Chart3D控件(在线文档'C1Chart3D类'),单击查看|属性窗体。
  2. 通过单击Legend属性旁边的下拉箭头添加一个图例,并选择C1Chart3DLegend (在线文档'C1Chart3DLegend 类')。在下一步中,您将运行该项目并查看新创建的图表。第五步:运行该工程

在这一步中,您将运行该项目以查看图表。选择开始|调试或按F5键。您会看到Chart3D图例。

恭喜完成!您已经完成了WPF和Silverlight版Chart3D的快速入门。

  • No labels