Asp.net chart控件做饼图数据如何显示在外面

.Net技术 码拜 9年前 (2015-02-18) 1882次浏览 0个评论

如题,图显示正常,但是我想把每一个小扇形的数字在扇形外显示,this.ChartPie.Series[“Series2”][“PieLabelStyle”] = “Outside”; 这句话不起作用,看图Asp.net chart控件做饼图数据如何显示在外面

 
Asp.net chart控件做饼图数据如何显示在外面
30分
选中系列,前端设置CustomProperties=”PieLabelStyle=Outside”
Asp.net chart控件做饼图数据如何显示在外面
引用 1 楼 apollokk 的回复:

选中系列,前端设置CustomProperties=”PieLabelStyle=Outside”

Asp.net chart控件做饼图数据如何显示在外面  是这样用吧,还是没有作用呢,怎么回事呢。。。

Asp.net chart控件做饼图数据如何显示在外面
还要IsValueShownAsLabel=”True”
Asp.net chart控件做饼图数据如何显示在外面
Asp.net chart控件做饼图数据如何显示在外面
Asp.net chart控件做饼图数据如何显示在外面 哎呀,前端显示时正常了按你的方法,但是调试起来硬是不好用,后台写的有问题吗Asp.net chart控件做饼图数据如何显示在外面
Asp.net chart控件做饼图数据如何显示在外面
10分
饼型分析投票结果–图、表统计
 public void CreatePieImage()
    {
        //定义数据库连接字符串
        string connString = System.Configuration.ConfigurationManager.AppSettings[“conn”].ToString();
        //建立与数据库连接的对象
        SqlConnection conn = new SqlConnection(connString);
        //打开数据库连接
        conn.Open();
        //定义查询数据库的SQL语句
        string cmdtxt = “select * from tb_vote”;
        //定义一个SqlCommand命令对象
        SqlCommand comm = new SqlCommand(cmdtxt, conn);
        //定义一个数据
        DataSet ds = new DataSet();
        //定义一个数据适配器
        SqlDataAdapter da = new SqlDataAdapter(comm);
        //填充数据集
        da.Fill(ds);
        conn.Close();
        float Total = 0.0f, Tmp;
        int iLoop;
        for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++)
        {
            //转换成单精度,也可以写成Convert.ToInt32
            Tmp = Convert.ToSingle(ds.Tables[0].Rows[iLoop][“投票数量”]);
            Total += Tmp;
        }
        //设置字体,fontTitle为主标题的字体
        Font fontLegend = new Font(“verdana”,9),fontTitle = new Font(“verdana”,10,FontStyle.Bold);
        //设置背景宽
        int width = 250;
        int bufferspase = 15;
        int legendheight = fontLegend.Height * (ds.Tables[0].Rows.Count + 1) + bufferspase;
        int titleheight = fontTitle.Height+bufferspase;
        //设置白色背景高
        int height = width + legendheight + titleheight + bufferspase;
        int pieheight = width;
        Rectangle pierect = new Rectangle(0,titleheight,width,pieheight);
        //加上各种随机色
        ArrayList colors = new ArrayList();
        //生成伪随机生成器
        Random rnd = new Random();
        for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++)
            colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));
        //创建一个bitmap实例
        Bitmap objbitmap = new Bitmap(width,height);
        Graphics objgraphics = Graphics.FromImage(objbitmap);
        //画一个白色背景
        objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
        //画一个亮黄色背景
        objgraphics.FillRectangle(new SolidBrush(Color.LightYellow),pierect);
        //以下为画饼型图(有几行row画几个)
        float currentdegree = 0.0f;
        for(iLoop = 0; iLoop<ds.Tables[0].Rows.Count;iLoop++)
        {
            objgraphics.FillPie((SolidBrush)colors[iLoop],pierect,currentdegree,
                Convert.ToSingle(ds.Tables[0].Rows[iLoop][“投票数量”]) / Total * 360);
            currentdegree += Convert.ToSingle(ds.Tables[0].Rows[iLoop][“投票数量”]) / Total * 360;
        }//codego.net/tags/11/1/
        //以下生成主标题
        SolidBrush blackbrush = new SolidBrush(Color.Black);
        string title = “明日科技图书投票调查结果”;
        //封闭文本局部信息
        StringFormat Format = new StringFormat();
        //设置垂直面上的文本信息位置居中
        Format.Alignment = StringAlignment.Center;
         //设置水平面上的文本信息位置居中
        Format.LineAlignment = StringAlignment.Center;
        objgraphics.DrawString(title,fontTitle,blackbrush,
            new Rectangle(0,0,width,titleheight),Format);
        //列出各字段与得数目
        objgraphics.DrawRectangle(new Pen(Color.Black, 2), 0, height – legendheight, width, legendheight);
        for(iLoop = 0;iLoop<ds.Tables[0].Rows.Count;iLoop++)
        {
            objgraphics.FillRectangle((SolidBrush)colors[iLoop],5,height – legendheight + fontLegend.Height * iLoop+5,10,10);
            //读出数据库中的“图书名称”、“投票数量”信息
            objgraphics.DrawString(((String)ds.Tables[0].Rows[iLoop][“图书名称”]) +”(” +(ds.Tables[0].Rows[iLoop][“投票数量”])+”票”+”)”+ “——” + Convert.ToString(Convert.ToSingle(ds.Tables[0].Rows[iLoop][“投票数量”]) * 100 /Total).Substring(0, 5) + “%”, fontLegend, blackbrush,
            20, height – legendheight + fontLegend.Height * iLoop + 1);
        }
        //图像总的高度-一行字体的高度,即是最底行的一行字体高度(height – fontLegend.Height )
        objgraphics.DrawString(“明日图书投票总数是:” + Convert.ToString(Total), fontLegend, blackbrush, 5, height – fontLegend.Height);
        //输出图片格式为gif
        Response.ContentType = “image/gif”;
        objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        objgraphics.Dispose();
        objbitmap.Dispose();
    }
Asp.net chart控件做饼图数据如何显示在外面
我用的chart控件,基本完成了,不想再从新自己画了。。。谢谢
Asp.net chart控件做饼图数据如何显示在外面
引用 3 楼 apollokk 的回复:

还要IsValueShownAsLabel=”True”
img src=”http://img.bbs.csdn.net/upload/201501/14/1421198009_926567.png” alt=””>

  问题已经解决,是后台我只是加到集合中显示出来 ,没有具体绑定到Series1中了,修改为     ChartPie.Series[“Series2”].Points.AddXY(m, zh002_002);//将累计时间和房号存储在集合中,成功了 ,多谢你!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Asp.net chart控件做饼图数据如何显示在外面
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!