您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        昨天要求弄个显示数据的图表。这可难到了我这个大菜鸟。费了九牛二虎之力,才勉强弄了个东西出来。先记录在这里了,免得以后长时间不用又忘记了。
1.先在http://www.carlosag.net/Tools/WebChart/下载一个webchart的控件,放到你的工程项目中。然后添加引用,就能拖控件了。
2.拖这个控件到aspx页面中
前台:
- <div id="Div2" runat="server">
 - <Web:ChartControl ID="myPieChart" runat="server" Width="400"
 - HasChartLegend="true">
 - </Web:ChartControl>
 - <Web:ChartControl ID="myChartControl" runat="server" Width="600"
 - HasChartLegend="false" ChartPadding="50">
 - </Web:ChartControl>
 - </div>
 
后台:
- //实例化两个chart对象
 - PieChart pC = new PieChart();
 - ColumnChart cC = new ColumnChart();
 - //饼图颜色
 - pC.Colors = new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Cyan, Color.AntiqueWhite, Color.RosyBrown };
 - //需要绑定的数据
 - int IContracting = Int32.Parse(Contracting.Text);
 - int INearlyEnd = Int32.Parse(NearlyEnd.Text);
 - int IContractYear = Int32.Parse(ContractYear.Text);
 - int IContractSign = Int32.Parse(ContractSign.Text);
 - int IAlreadyEnd = Int32.Parse(AlreadyEnd.Text);
 - int SignIn = IContractSign - IAlreadyEnd;
 - //绑定数据到饼图并显示
 - pC.Data.Add(new ChartPoint("已结束的合同", SignIn));
 - pC.Data.Add(new ChartPoint("未结束的合同", INearlyEnd));
 - pC.DataLabels.Visible = true;
 - pC.DataLabels.NumberFormat = "N";
 - pC.DataLabels.ForeColor = Color.Black;
 - myPieChart.Charts.Add(pC);
 - myPieChart.RedrawChart();
 - //绑定数据到柱状图并显示
 - cC.Data.Add(new ChartPoint("合同中的工程", IContracting));
 - cC.Data.Add(new ChartPoint("即将结束的合同", INearlyEnd));
 - cC.Data.Add(new ChartPoint("今年将结束的合同", IContractYear));
 - cC.Data.Add(new ChartPoint("已签约的合同", IContractSign));
 - cC.Fill.Color = Color.Blue;
 - cC.Shadow.Color = Color.Red;
 - cC.DataLabels.Visible = true;
 - cC.MaxColumnWidth = 40;
 - myChartControl.Charts.Add(cC);
 - myChartControl.RedrawChart();
 
写完代码后,调试效果如下:

如上,虽然效果很粗糙,但至少弄出来了。
接下来就准备研究下在.net中调用swf画图
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。