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 ...
随机推荐
- [Ubuntu] google chrome乱码
问题描述 ubuntu14.04,之前google chrome一直都是好好的,升级过相关软件,之后就是乱码了,如图 经过google的努力,找到解决方法,原因未明. 解决方案 sudo /etc/f ...
- javascript中字符串格式json如何转化成json对象
什么是JSON JSON(JavaScript Object Notation)是一种优美的JavaScript对象创建方法.JSON也是一种轻量级数据交换格式.JSON非常易于人阅读与编写,同时利于 ...
- onTouch和onTouchEvent
public boolean dispatchTouchEvent(MotionEvent event) { if (mOnTouchListener != null && mOnTo ...
- Unable to resolve target 'android-19'
修改两个地方,解决上面的问题
- 加载执行预编译的Sql :prepareStatement
1.获得连接:Connection con = null; con = DBUtil.getConnection(); 2.写sql语句:String sql=""; 3.用连接加 ...
- python 提取图片转为16 24BPP 的方法
python 中处理图片用的是 pil ,在 linux 和 win 上都可以使用. centOS 5.x 上安装的方法是 yum install python-imaging 24BPP: imp ...
- struts2-json-plugin插件实现异步通信
用例需要依赖的jar: struts2-core.jar struts2-convention-plugin.jar,非必须, struts2-json-plugin.jar org.codehaus ...
- Hibernate,JPA注解@ManyToMany
@ManyToMany默认处理机制,当双向多对多关联中没有定义任何物理映射时, Hibernate根据以下规则生成相应的值: 关联表名: 主表表名+_下划线+从表表名: 关联到主表的外键名:从表用于关 ...
- Hibernate,JPA注解@Version
Hibernate实现悲观锁和乐观锁. 1,悲观锁 用例代码如下: 数据库DDL语句: hibernate.cfg.xml java类 以上代码(除下面的main之外)同乐观锁. main packa ...
- HDU 3076:ssworld VS DDD(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description One day, s ...