原創|其它|編輯:郝浩|2012-10-18 15:44:15.000|閱讀 1013 次
概述: Visifire for Silverlight/WPF制作透明圖表的例子和大家分享一下。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
這里將Visifire for Silverlight/WPF實例教程分享給大家,希望對大家有幫助!
網上Silverlight實例教程有很多,但在這些Silverlight實例教程中有也有很多沒有價值,我覺得這一篇有些用處所以分享給大家!
使用Visifire創建的圖表,默認的是帶邊框、背景色(使用Xaml代碼創建的圖表默認背景是透明的,使用C#代碼創建的圖表默認背景色是白色的)、坐標和圖表格(ChartGrid)的,有時為了實現特殊的需求,需要將圖表的背景做成透明的。在Xaml代碼中,可以通過設置Chart的 “BorderThickness”屬性為“0”和Axis的“Enabled”屬性為“False”輕松實現透明效果。
下面我們通過C#代碼來實現 Visifire圖表的透明效果。
/*****第一段代碼*****/ Chart chart = new Chart(); chart.Width = 400; chart.Height = 300; DataSeries dataSeries = new DataSeries(); dataSeries.RenderAs = RenderAs.Column; dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "Wall-Mart", YValue = 351139 }); dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "Exxon Mobil", YValue = 345254 }); dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "Shell", YValue = 318845 }); dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "BP", YValue = 274316 }); dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "General Motors", YValue = 207349 }); chart.Series.Add(dataSeries); chart.SetValue(Grid.ColumnProperty, 1); LayoutRoot.Children.Add(chart);
去掉圖表的邊框和背景色,在上面的代碼第3行后面加入下面的代碼:
/*****第二段代碼*****/ //將邊框設為0 c hart.BorderThickness = new Thickness(0);// 將背景色設為透明6 chart.Background = new SolidColorBrush(Colors.Transparent);
去掉坐標軸,接著上第二段代碼再加入下面的代碼:
/*****第三段代碼*****/ //去掉X軸 Axis xaxis = new Axis(); xaxis.Enabled = false; chart.AxesX.Add(xaxis); //去掉Y軸 Axis yaxis = new Axis(); yaxis.Enabled = false; chart.AxesY.Add(yaxis);
最后再去掉圖表格,在第三段代碼的第5行和第10行下面分別插入下面的代碼:
//插入第三段代碼第5行后面 ChartGrid xgrid = new ChartGrid(); xgrid.Enabled = false; xaxis.Grids.Add(xgrid); //插入第三段代碼第10行后面 ChartGrid ygrid = new ChartGrid(); ygrid.Enabled = false; yaxis.Grids.Add(ygrid);
至此我們就將Visifire圖表設置成透明的了。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:云世界