饼块遮挡该怎么解决呢?

解决方案 »

  1.   

    1、首先下载ZedGraph.dll和ZedGraph.Web.dll文件,引用到项目中,在选择项添加ZedGraphWeb控件。将ZedGraphWeb控件拖到页面如果程序报错无法加载,检查页面是否有<%@ Register Assembly="ZedGraph.Web" Namespace="ZedGraph.Web" TagPrefix="cc1" %>注册代码,并将dll从项目删除,重新引用。多试几次 2、页面加载控件无误后: protected void Page_Load(object sender, EventArgs e)
            {ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(ZedGraphWeb1_RenderGraph);//注册事件 } 
    //创建饼图private void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
            {
                graphPane = pane[0];                             // 在此之前定义全局变量GraphPane graphPane;
                grap = g;            // 在此之前定义全局变量System.Drawing.Graphics grap;
                graphPane.Title.Text = “数据统计”;    //给饼图设置title   
                DrawPie(type);                                        //具体画图的方法
                graphPane.AxisChange(g);                  
            }
    //对饼图的具体操作private void DrawPie(int num){            DataTable dtyear = new DataTable(); //用于绑定ZedGraphWeb数据
                double huikuan = new double();       
                int zonge = 0; 
               。。 给dtyear 赋值省略graphPane.Title.Text = titlehehe;
                    graphPane.CurveList.Clear();
                    graphPane.GraphObjList.Clear();
                    // Set the GraphPane title
                    graphPane.Title.FontSpec.IsItalic = true;
                    graphPane.Title.FontSpec.Size = 24f;
                    graphPane.Title.FontSpec.Family = "Times New Roman";                // Fill the pane background with a color gradient
                    graphPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
                    // No fill for the chart background
                    graphPane.Chart.Fill.Type = FillType.None;                // Set the legend to an arbitrary location
                    graphPane.Legend.Position = LegendPos.Float;
                    graphPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction,
                                   AlignH.Right, AlignV.Top); //设置饼图显示位置
                    graphPane.Legend.FontSpec.Size = 10f; //设置字体大小 
                    graphPane.Legend.IsHStack = false;
                    TextObj text = new TextObj("", 0.18F, 0.40F, CoordType.ChartFraction);
                    graphPane.Fill = new Fill(Color.White, Color.Silver, 45.0f);                graphPane.Legend.Position = LegendPos.Float;
                    graphPane.Legend.Location = new Location(0.99f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top);
                    graphPane.Legend.FontSpec.Family = "宋体";
                    graphPane.Legend.FontSpec.Size = 10;
                    graphPane.Legend.IsHStack = false;                               具体按数据画图                 double y = 0.00;
                        string name1 = "";
                        for (int i = 0; i < dtyear.Rows.Count; i++)
                        {
                            y = Convert.ToDouble(string.IsNullOrEmpty(dtyear.Rows[i]["金额"].ToString()) == true ? "0" : dtyear.Rows[i]["金额"].ToString());
                            name1 = dtyear.Rows[i]["日期"].ToString() + "," + dtyear.Rows[i]["金额"].ToString();
                            graphPane.AddPieSlice(y, GetRandomColor(), Color.White, 45f, 0, name1);
                        }
                        dtyear.Rows.Add(new object[] { "总额", huikuan.ToString() });
                        GridView1.DataSource = dtyear;    //如果要求下面显示列表数据时,给GridView1绑定数据
                        GridView1.DataBind();
                        dtyear = null;
                        CurveList curves = graphPane.CurveList;
                        double total = 0;
                        for (int x = 0; x < curves.Count; x++)
                            total += ((PieItem)curves[x]).Value;
                        // Make a text label to highlight the total value
                        text.Text = "总额" + huikuan.ToString();                         
                          text.Location.AlignH = AlignH.Center;
                    text.Location.AlignV = AlignV.Bottom;
                    text.FontSpec.Border.IsVisible = false;
                    text.FontSpec.Fill = new Fill(Color.White, Color.FromArgb(255, 100, 100), 45F);
                    text.FontSpec.StringAlignment = StringAlignment.Center;
                    graphPane.GraphObjList.Add(text);
                    // Create a drop shadow for the total value text item
                    TextObj text2 = new TextObj(text);
                    text2.FontSpec.Fill = new Fill(Color.Black);
                    text2.Location.X += 0.008f;
                    text2.Location.Y += 0.01f;
                    graphPane.GraphObjList.Add(text2);
                    graphPane.AxisChange(grap);
    }
    3、创建随机颜色,设置饼图大小
    // 创建随机颜色private Color GetRandomColor()
            {
                Random RandomNum_First = new Random((int)DateTime.Now.Ticks);          
                System.Threading.Thread.Sleep(RandomNum_First.Next(150));
                Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
                System.Threading.Thread.Sleep(RandomNum_Sencond.Next(150));
                Random RandomNum_3 = new Random((int)DateTime.Now.Ticks);            int int_Red = RandomNum_First.Next(256);
                int int_Green = RandomNum_Sencond.Next(256);
                int int_Blue = RandomNum_3.Next(256);
                // 为了在白色背景上显示,尽量生成深色 
                //int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
                //int_Blue = (int_Blue > 255) ? 255 : int_Blue;            return Color.FromArgb(int_Red, int_Green, int_Blue);
            }//设置大小及字体private void SetSize()
            {
                //保留一个小的页面空白在控件的周围
                ZedGraphWeb1.Width = 1000;
                ZedGraphWeb1.Height = 500;
                ZedGraphWeb1.FontSpec.Family = "宋体";
                ZedGraphWeb1.FontSpec.Size = 12;
            }