ZedGraph控件,饼图中加入“其它”块,记录项目中的实际实现

当饼图的分块大于10块的时候,往往会显得很杂乱,标签可能会叠加到一起,所以应该在饼图中加入“其它”块,把那些top10分开表示,剩下的就可以放在“其它”块里,这样界面较美观,以下为代码实现

其中dataRowPro 为datatable中的datarow

 

<textarea name="code" class="c-sharp" rows="15" cols="50">private string m_strColumn = string.Empty; // 显示该列的数字 private string m_strName = string.Empty; // 显示列名 ArrayList dataRowProList = new ArrayList(); Hashtable htShowName = new Hashtable(); if (dataRowPro.Length > 10) //当分类大于10的时候 { for (int i = 0; i < dataRowPro.Length; i++) { dataRowProList.Add(Convert.ToDouble(dataRowPro[i][m_strColumn])); htShowName.Add(dataRowProList[i], dataRowPro[i][m_strShowName].ToString().Trim()); } dataRowProList.Sort(); for (int i = 0; i < dataRowProList.Count - 1; i++) { dataRowPro[i][m_strColumn] = dataRowProList[dataRowProList.Count - 1-i]; dataRowPro[i][m_strShowName] = htShowName[dataRowProList[dataRowProList.Count - 1 - i]].ToString(); } double totals = 0.0; for (int i = 0; i < 9; i++) { if (string.IsNullOrEmpty(dataRowPro[i][m_strColumn].ToString()) == true) { dataRowPro[i][m_strColumn] = "0"; } segment[i] = myPane.AddPieSlice(Convert.ToDouble(dataRowPro[i][m_strColumn]) / protypeTotal * 100, Color.Yellow, Color.Red, 450f, 0.1+i/50, dataRowPro[i][m_strShowName].ToString().Trim() + "(" + Math.Round(Convert.ToDouble(dataRowPro[i][m_strColumn]) / protypeTotal * 100, 2) + "%)"); totals += Convert.ToDouble(dataRowPro[i][m_strColumn]) / protypeTotal * 100; } totals = 100.00 - totals; segment[9] = myPane.AddPieSlice(totals, Color.GreenYellow, Color.Red, 40f, 0.1, "其它" + "(" + Math.Round(totals, 2) + "%)"); } else { for (int i = 0; i < dataRowPro.Length; i++) { if (string.IsNullOrEmpty(dataRowPro[i][m_strColumn].ToString()) == true) { dataRowPro[i][m_strColumn] = "0"; } segment[i] = myPane.AddPieSlice(Convert.ToDouble(dataRowPro[i][m_strColumn]) / protypeTotal * 100, Color.FromArgb(ra.Next(2, 255), ra.Next(3, 235), ra.Next(4, 200)), Color.Red, 40f, 0.1, dataRowPro[i][m_strShowName].ToString().Trim() + "(" + Math.Round(Convert.ToDouble(dataRowPro[i][m_strColumn]) / protypeTotal * 100, 2) + "%)"); } } masterPane.AxisChange(); </textarea> 


 

 

    这是部分逻辑代码实现,只要实现了datarowpro,以下代码可直接用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ZedGraph饼图、条形图和饼图Demo源码 ZedGraphV515是C#编写的.NET类库,提供了用户控件和web控件。它可以创建2D的线性图、条形图和饼图。 它功能完整且有详细的功能自定义。 基于LGPL协议开源,.NET 2.0 C#源代码)它的思路清淅,所以非常容易就上手. 几个注意点: 图片的保存路径设置:RenderedImagePath属性设置,程序对该文件夹应该是有写和修改权限的 图片的输出格式:OutputFormat属性设置,Png的推荐,比较清晰。 Chart ChartBorder 图表区域的边框设置 ChartFill 图表区域的背景填充 Legend 图表的注释标签显示设置项目,一组数据对应一种颜色的注释 IsHStack 当有多个显示项的时候设置Y轴数据是叠加的还是分开的 Xaxis 图表区域的X轴相关信息设置 AxisColor 坐标轴颜色 Cross 坐标的原点,可以设置坐标的偏移程度 CrossAuto 原点自动设置:True的话Cross的设置就无效了。 FontSpec X轴标题字体相关信息 Angle X轴标题字体显示时候的角度,0为水平 90为垂直 Fill X轴标题字体填充信息 ColorOpacity 透明度 IsScaled 设置X轴标题字体显示大小是否根据图的比例放大缩小 RangeMax 填充时候的最大倾斜度(有过渡色,没试过) RangeMin 填充时候的最小倾斜度(有过渡色,没试过) StringAlignment X轴标题字体排列(不清楚,没试过) IsOmitMag 是否显示指数幂(10次方,没试过,似乎与IsUseTenPower有关系) IsPreventLabelOverlap 坐标值显示是否允许重叠,如果False的话,控件会根据坐标值长度自动消除部分坐标值的显示状态 IsShowTitle X轴标题是否显示 IsTicsBetweenLabels 两个坐标值之间是否自动显示分隔标志 IsUseTenPower 是否使用10次幂指数 IsVisible 是否显示X轴
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值