MSChart使用

制作报表的时候结果出现画红线处的信息太散,
如果没必要全部显示出来,我们可以使用这种效果:

注意和前面的区分,这个功能叫做Collect Pie Slices(收集分区)

要实现此功能,应先了解相关信息
1.收集的阀值(Collected Threshold)
比如这张图我们设置当百分比小于多少5%时集中。
2.集合区要显示的文本(Collected Label)
比如我们这里集合区域(饼状图绿色部分)内显示的Other
3.图例文本(标签)(CollectedLegendText)
即我们饼状图的图例(右上角),显示的文本
4.合并区域显示的颜色(CollectedColor)
效果
5.合并后的区域是否突出(CollectedSliceExploded)
效果:
6.效果:

实现红线处上面为数量,下面为所占百分比:
var servers = Chart1.Series[0];
servers.Label = "#VAL\r\n#PERCENT{P1}";
实例:
html:
<asp:Chart ID="Chart1" runat="server" Palette="BrightPastel" BackColor="#D3DFF0" BorderDashStyle="Solid" BackSecondaryColor="White"
BackGradientStyle="TopBottom" BorderWidth="2" BorderColor="26, 59, 105" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)" ImageType="Png">
<Titles>
<asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3" Text="Pie Chart" Name="Title1" ForeColor="26, 59, 105"></asp:Title>
</Titles>
<Legends>
<asp:Legend Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold" Enabled="True" ></asp:Legend>
</Legends>
<BorderSkin SkinStyle="Emboss"></BorderSkin>
<Series>
<asp:Series Name="Default" ChartType="Pie" XValueType="Double" BorderColor="180, 26, 59, 105" ShadowOffset="5"
Font="Trebuchet MS, 8.25pt, style=Bold" YValueType="Double" ></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BackSecondaryColor="White" BackColor="Transparent" ShadowColor="" BorderWidth="0">
<Area3DStyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="False" WallWidth="0" IsClustered="False"></Area3DStyle>
<AxisY LineColor="64, 64, 64, 64">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisY>
<AxisX LineColor="64, 64, 64, 64">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
// Create pie chart helper class,
pieHelper = new PieCollectedDataHelper(Chart1);
pieHelper.CollectedLabel = String.Empty; // Set chart type ,设置图标类型,饼状图Pie 环装图:Doughnut
//Chart1.Series["Default"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ChartTypeList.SelectedItem.Text, true);
Chart1.Series["Default"].ChartType = SeriesChartType.Pie; // Set chart type and title
//需要配合Titles
Chart1.Titles[0].Text = "后整产量" + " Chart"; //ShowLegend显示标签,Disabled隐藏 Inside内部显示,Outside外部显示 Chart1.Series["Default"]["PieLabelStyle"] = "Outside"; // Set Doughnut hole size,甜甜圈宽度,,只有当 Chart1.Series["Default"].ChartType=="Doughnut"才生效
Chart1.Series["Default"]["DoughnutRadius"] = "60";
//Docking
//需要配合Legends
//调整Legends位置
Chart1.Legends[0].Docking = Docking.Bottom; //Alignment="Center" Docking="Bottom" IsTextAutoFit="False" LegendStyle="Row" //LegendStyle // Enable 3D
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false; //甜甜圈图样式Default SoftEdge Concave,,当启动3D模式时设置不生效
Chart1.Series[0]["PieDrawingStyle"] = "SoftEdge"; //// Pie drawing style
//if (this.CheckboxShow3D.Checked)
// this.Dropdownlist1.Enabled = false; //else
// this.Dropdownlist1.Enabled = true; // Populate series data
double[] yValues = { 9042, 558, 2160, 4051, 2151, 1761 };
string[] xValues = { "A64", "A65", "A66", "A67", "A68", "A69"}; DataTable dt = CreateData(); var v = ToList<HZProducte>(dt); //double[] yValues = { 65.62, 2.1, 85.73, 11.42, 34.45, 75.54, 5.7, 4.1 };
//string[] xValues = { "France", "Japan", "USA", "Italy", "Germany", "Canada", "Russia", "Spain" }; //具有绑定规则的其他数据点属性,格式为:PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]]。例如:“Tooltip=Price{C1},Url=WebSiteName”。
//Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);<!--Label="#PERCENT{P1}-->" /*
MSChart的Label的值的转义符,如下:
#VALX 显示当前图例的X轴的对应文本(或数据)
#VAL, #VALY, 显示当前图例的Y轴的对应文本(或数据)
#VALY2, #VALY3, 显示当前图例的辅助Y轴的对应文本(或数据)
#SER: 显示当前图例的名称
#LABEL 显示当前图例的标签文本
#INDEX 显示当前图例的索引
#PERCENT 显示当前图例的所占的百分比
#TOTAL 总数量
#LEGENDTEXT 图例文本 当LegendText为#AXISLABEL时,如果Label为#PERCENT,并且绑定的ValueMember为数值时,LegendText显示的和Label一样,存在Bug。
*/
var servers = Chart1.Series[0];
servers.Label = "#VAL\r\n#PERCENT{P1}";
//Chart1.DataSource = dt;
//servers.XValueMember = "CenterName";
//servers.YValueMembers = "Qty";
//servers.LegendText = "#VALX";
//Chart1.DataBind();
//servers.LabelBackColor = Color.Red;
//servers.LabelUrl = "http://www.baidu.com"; servers.Points.DataBind(v, "CenterName", "Qty", "LegendText=CenterName"); pieHelper.SupplementedAreaSizeRatio = 3.0f; } public class HZProducte
{
public int Qty { set; get; } public string CenterName { get; set; }
} DataTable CreateData()
{ DataTable dt = new DataTable(); #region 准备Dt
dt.Columns.Add("Qty", typeof(System.Int32));
dt.Columns.Add("CenterName", typeof(System.String)); DataRow row1 = dt.Rows.Add();
row1["Qty"] = 9042;
row1["CenterName"] = "后整一厂"; DataRow row2 = dt.Rows.Add();
row2["Qty"] = 558;
row2["CenterName"] = "后整二厂"; DataRow row3 = dt.Rows.Add();
row3["Qty"] = 2160;
row3["CenterName"] = "后整三厂"; DataRow row4 = dt.Rows.Add();
row4["Qty"] = 4051;
row4["CenterName"] = "后整四厂"; DataRow row5 = dt.Rows.Add();
row5["Qty"] = 2151;
row5["CenterName"] = "后整五厂"; DataRow row6 = dt.Rows.Add();
row6["Qty"] = 1761;
row6["CenterName"] = "后整六厂"; #endregion
return dt;
} /// <summary>
/// DataTable 转换为List 集合
/// </summary>
/// <typeparam name="TResult">类型</typeparam>
/// <param name="dt">DataTable</param>
/// <returns></returns>
public static List<TResult> ToList<TResult>(DataTable dt) where TResult : class, new()
{
//创建一个属性的列表
List<PropertyInfo> prlist = new List<PropertyInfo>();
//获取TResult的类型实例 反射的入口
Type t = typeof(TResult);
//获得TResult 的所有的Public 属性 并找出TResult属性和DataTable的列名称相同的属性(PropertyInfo) 并加入到属性列表
Array.ForEach<PropertyInfo>(t.GetProperties(), p => { if (dt.Columns.IndexOf(p.Name) != -1) prlist.Add(p); });
//创建返回的集合
List<TResult> oblist = new List<TResult>(); foreach (DataRow row in dt.Rows)
{
//创建TResult的实例
TResult ob = new TResult();
//找到对应的数据 并赋值
prlist.ForEach(p => { if (row[p.Name] != DBNull.Value) p.SetValue(ob, row[p.Name], null); });
//放入到返回的集合中.
oblist.Add(ob);
}
return oblist;
}
设置Collected相关代码
if (this.chk_Pie.Checked)
{
comboBoxChartType.Enabled = true;
comboBoxCollectedColor.Enabled = true;
comboBoxCollectedThreshold.Enabled = true;
textBoxCollectedLabel.Enabled = true;
textBoxCollectedLegend.Enabled = true;
this.ShowExplode.Enabled = true; // Set the threshold under which all points will be collected
series1["CollectedThreshold"] = comboBoxCollectedThreshold.SelectedItem.ToString(); // Set the label of the collected pie slice
series1["CollectedLabel"] = textBoxCollectedLabel.Text; // Set the legend text of the collected pie slice
series1["CollectedLegendText"] = textBoxCollectedLegend.Text; // Set the collected pie slice to be exploded
series1["CollectedSliceExploded"]= this.ShowExplode.Checked.ToString(); // Set collected color
series1["CollectedColor"] = comboBoxCollectedColor.SelectedItem.ToString(); // Set chart type
series1.ChartType = (SeriesChartType) Enum.Parse( typeof(SeriesChartType), comboBoxChartType.SelectedItem.ToString(), true );
} else
{
series1["CollectedThreshold"] = "0";
comboBoxChartType.Enabled = false;
comboBoxCollectedColor.Enabled = false;
comboBoxCollectedThreshold.Enabled = false;
textBoxCollectedLabel.Enabled = false;
textBoxCollectedLegend.Enabled = false;
this.ShowExplode.Enabled = false;
}
MSChart使用的更多相关文章
- MSChart绘图控件中折线图和柱形图画法
		首先在前台拖入一个名为chart1的MSChart控件 //折线图 string strLegend = "Legend1"; Legend lg = new Legend(str ... 
- msChart组件安装与编程
		首先下载mschart.ocx文件,至于它所依赖的.net环境,网上有很多,本人下载的插件给出链接,http://www.cr173.com/soft/47300.html而它所依赖的环境可以从我的云 ... 
- MSChart参考
		MSChart在vs2008中使用遇到一个问题,坐标轴的标题为中文时被图表区域遮挡了一部分. 解决办法:在说明文字前加\n实现换一行显示. //this.Chart1.ChartAreas[0].Ax ... 
- C# WinForm动态添加MSChart控件
		添加mschart.dll动态链接库 添加引用 System.Windows.Forms.DataVisualization MSChart控件作为方便的用户数据展示控件,可以方便的使用控件提 ... 
- 图表控件MsChart使用demo
		chart 控件主要有 Titles 标题集合 Chart Area图形显示区域 Series图表集合 Legends图列的集合 (1) 常用事件: 1. Series1.Points.DataB ... 
- MSChart 控件
		微软发布了.NET 3.5框架下的图表控件,功能很强劲,基本上能想到的图表都可以使用它绘制出来,给图形统计和报表图形显示提供了很好的解决办法,同时支持Web和WinForm两种方式,不过缺点也比较明显 ... 
- MSChart实例
		MSChart是VS中自带的图表控件,功能比较强大,效果也比较丰富.下面只提供一个例子,以供新接触的朋友参考. 先看下效果图: 看完效果图上代码啦. 使用这个控件需要先在页面注册一下. <%@ ... 
- 利用MsChart控件绘制多曲线图表  z
		在.Net4.0框架中,微软已经将Mschart控件集成了进来,以前一直在web下面用过,原来winform下的Mschart控件更加简单更加方便,今天我们用mschart绘制一个多曲线图,话不多说, ... 
- MSChart使用之双Y轴使用
		protected void SearchChart() { Chart1.ChartAreas.Clear(); Chart1.Series.Clear(); ChartArea _ChartAre ... 
随机推荐
- 手机端js事件支持(event)
			http://blog.163.com/rex_blog/blog/static/1944801012013102743014369/ 所有被测试的浏览器都支持touchstart.touchend和 ... 
- zw版【转发·台湾nvp系列Delphi例程】HALCON EdgesImage
			zw版[转发·台湾nvp系列Delphi例程]HALCON EdgesImage procedure TForm1.Button1Click(Sender: TObject);var img0, im ... 
- linux计划任务运行php文件的方法
			在linux下,借助crontab,设置计划任务每天6点10分执行filename.php文件,写入一行时间到log日志中. 创建计划任务的脚本: dos2unix /path/to/filename ... 
- asp.net中获得客户端的IP地址
			asp.net中获得客户端的IP地址 因为要在项目中取到客户端IP,在网上搜了下相关资料,其中有一篇文章总结的比较详细,这里就把一些我用的上总结一下 方便以后查阅. 通常我们都通过下面的代码获得IP ... 
- 绑定repeater时三目运算加特殊结果处理
			<%#((Convert.ToDouble().ToString() != ).ToString(% 
- Linode 优惠码
			Linode 是最好的vps $10的优惠码 Linode10,推荐码:bc7852453e280eee5a8ef045c5ab54ca091c8021 链接https://www.linode.co ... 
- 【NOIP模拟赛】lover——心上人
			心上人 [问题描述] 人到初三,总会遇到情感问题,比方说小 J 就喜欢上了小 W.于是小 J 就需要说一长串的话讨小 W 欢心.现在已知小 W 听到一些词就会很高兴,而且白听不厌,但她又讨厌小 J ... 
- HashMap存值
			package com.exmple.tool; import java.util.HashMap; public class UserTool { public static HashMap< ... 
- React笔记_(2)_react语法1
			这一节内容主要以了解为主. 渐渐的体会react的语法和其特性. ① htmlAndJs 混合编写 react和以往的前后台书写方式不一样. 在之前的多个语言中,讲求的是将页面代码和js代码逻辑分开, ... 
- laravel运行url404错误
			url输入正确的根目录时老是提示404错误,竟然不知道为什么,稀里糊涂的,最后发现输入url时后面默认会加上一个\,一定记得把\去掉!!!! 
 
			
		
