使用Visifire制作透明图表

    本文短地址:http://zdd.me/kpgjv

 

    Visifire是一个基于Silverlight & WPF的可视化图表组件,使用Visifire可以轻松创建出可嵌入桌面程序或Web程序的动态图表。

    使用Visifire创建的图表,默认的是带边框、背景色(使用Xaml代码创建的图表默认背景是透明的,使用C#代码创建的图表默认背景色是白色的)、坐标和图表格(ChartGrid)的,有时为了实现特殊的需求,需要将图表的背景做成透明的。在Xaml代码中,可以通过设置Chart的“BorderThickness”属性为“0”和Axis的“Enabled”属性为“False”轻松实现透明效果。下面我们通过C#代码来实现Visifire图表的透明效果。

    首页使用下面的代码创建一个图表

1 /*****第一段代码*****/
2
3 Chart chart = new Chart();
4 chart.Width = 400;
5 chart.Height = 300;
6 chart.DataPointWidth = 10; // 通过Chart的DataPointWidth属性控制DataPoint的宽度
7 DataSeries dataSeries = new DataSeries();
8 dataSeries.RenderAs = RenderAs.Column;
9 dataSeries.DataPoints.Add(new DataPoint
10 {
11 AxisXLabel = "Wall-Mart",
12 YValue = 351139
13 });
14 dataSeries.DataPoints.Add(new DataPoint
15 {
16 AxisXLabel = "Exxon Mobil",
17 YValue = 345254
18 });
19 dataSeries.DataPoints.Add(new DataPoint
20 {
21 AxisXLabel = "Shell",
22 YValue = 318845
23 });
24 dataSeries.DataPoints.Add(new DataPoint
25 {
26 AxisXLabel = "BP",
27 YValue = 274316
28 });
29 dataSeries.DataPoints.Add(new DataPoint
30 {
31 AxisXLabel = "General Motors",
32 YValue = 207349
33 });
34
35 chart.Series.Add(dataSeries);
36 chart.SetValue(Grid.ColumnProperty, 1);
37 LayoutRoot.Children.Add(chart);

 

去掉图表的边框和背景色,在上面的代码第3行后面加入下面的代码

1 /*****第二段代码*****/
2
3  //将边框设为0
4 chart.BorderThickness = new Thickness(0);
5 //将背景色设为透明
6 chart.Background = new SolidColorBrush(Colors.Transparent);

去掉坐标轴,接着上第二段代码再加入下面的代码

1 /*****第三段代码*****/
2
3 //去掉X轴
4 Axis xaxis = new Axis();
5 xaxis.Enabled = false;
6 chart.AxesX.Add(xaxis);
7
8 //去掉Y轴
9 Axis yaxis = new Axis();
10 yaxis.Enabled = false;
11 chart.AxesY.Add(yaxis);

最后再去掉图表格,在第三段代码的第5行和第10行下面分别插入下面的代码

1 //插入第三段代码第5行后面
2 ChartGrid xgrid = new ChartGrid();
3 xgrid.Enabled = false;
4 xaxis.Grids.Add(xgrid);
5
6 //插入第三段代码第10行后面
7 ChartGrid ygrid = new ChartGrid();
8 ygrid.Enabled = false;
9 yaxis.Grids.Add(ygrid);

至此我们就将Visifire图表设置成透明的了。

posted @ 2010-05-19 22:55  forgetu  阅读(2753)  评论(1编辑  收藏  举报