使用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图表设置成透明的了。

转载于:https://www.cnblogs.com/forgetu/archive/2010/05/19/visifire-transparent-chart.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值