博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MsChart中添加、删除Series
阅读量:6207 次
发布时间:2019-06-21

本文共 6843 字,大约阅读时间需要 22 分钟。

MsChart中添加、删除Series

前台
1  
2
5
6
8
9
10
11
12
13
14
15
16
17
18
19
20
22
24
25
26
27
28
29
30
31
33
34
35
36
37 虚线38
39
40

后台:

后台
1  #region 删除线或者添加线 2     ///  3     /// 删除线或者添加线 4     ///  5     ///  6     ///  7     protected void btnCh_Click(object sender, EventArgs e) 8     { 9         BindChart();10         this.chAnalysis.Visible = true;11         if (!chbox.Items[0].Selected)12         {13             for (int j = 0; j < this.chAnalysis.Series.Count; j++)14             {15                 if (this.chAnalysis.Series[j].Name == "ResultData")16                 {17                     this.chAnalysis.Series.Remove(this.chAnalysis.Series[j]);18                     break;19                 }20             }21         }22         if (!chbox.Items[1].Selected)23         {24             for (int j = 0; j < this.chAnalysis.Series.Count; j++)25             {26                 if (this.chAnalysis.Series[j].Name == "UpperLimit")27                 {28                     this.chAnalysis.Series.Remove(this.chAnalysis.Series[j]);29                     break;30                 }31             }32         }33         if (!chbox.Items[2].Selected)34         {35             for (int j = 0; j < this.chAnalysis.Series.Count; j++)36             {37                 if (this.chAnalysis.Series[j].Name == "LowerLimit")38                 {39                     this.chAnalysis.Series.Remove(this.chAnalysis.Series[j]);40                     break;41                 }42             }43         }44         BindDotLine();45         46     }47     #endregion48 49     public void BindDotLine()50     {51         double d = 0.0;52         if (!string.IsNullOrEmpty(this.txtLine.Text.Trim()))53         {54             if (!double.TryParse(this.txtLine.Text.Trim(), out d))55             {56                 return;57             }58             if (d > this.chAnalysis.ChartAreas[0].AxisY.Maximum)59             {60                 return;61             }62             if (d < this.chAnalysis.ChartAreas[0].AxisY.Minimum)63             {64                 return;65             }66             Series sline = new Series();67             sline.Name = "xuxian";68             sline.ChartType = SeriesChartType.Line;69             sline.BorderDashStyle = ChartDashStyle.Dot;70             if (ViewState["dt"] == null) { return; }71             DataTable dtResult = (DataTable)ViewState["dt"];72             for (int i = 0; i < dtResult.Rows.Count; i++)73             {74                 sline.Points.AddXY(dtResult.Rows[i]["batch_name"].ToString(), d);75             }76             sline.LegendText = "虚线";77             this.chAnalysis.Series.Add(sline);78         }
绑定
1  public void BindChart() 2     { 3         if (ViewState["dt"] == null) { return; } 4         DataTable dtResult = (DataTable)ViewState["dt"]; 5         this.chAnalysis.Series["ResultData"].PostBackValue = "#AXISLABEL"; 6         this.chAnalysis.Series["ResultData"].LegendText = "结果"; 7         this.chAnalysis.Series["ResultData"].MarkerStyle = MarkerStyle.Square; 8         this.chAnalysis.Series["ResultData"].ToolTip = "批次:\t#VALX\n结果:\t#VALY"; 9         this.chAnalysis.Series["UpperLimit"].MarkerStyle = MarkerStyle.Circle;10         this.chAnalysis.Series["UpperLimit"].LegendText = "上限";11         this.chAnalysis.Series["UpperLimit"].ToolTip = "上限:#VALY";12         this.chAnalysis.Series["LowerLimit"].MarkerStyle = MarkerStyle.Circle;13         this.chAnalysis.Series["LowerLimit"].LegendText = "下限";14         this.chAnalysis.Series["LowerLimit"].ToolTip = "下限:#VALY";15         this.chAnalysis.DataSource = dtResult;16         this.chAnalysis.Series["ResultData"].XValueMember = "batch_name";17         this.chAnalysis.Series["ResultData"].YValueMembers = "RESULTVALUE";18         this.chAnalysis.Series["LowerLimit"].XValueMember = "batch_name";19         this.chAnalysis.Series["LowerLimit"].YValueMembers = "MIN_LIMIT";20         this.chAnalysis.Series["UpperLimit"].XValueMember = "batch_name";21         this.chAnalysis.Series["UpperLimit"].YValueMembers = "MAX_LIMIT";22         this.chAnalysis.DataBind();23         DataTable newdt = CreateWarnTable();24         for (int j = 0; j < dtResult.Rows.Count; j++)25         {26             DataRow dr = newdt.NewRow();27             decimal lowerLimit = decimal.Parse(dtResult.Rows[j]["MIN_LIMIT"].ToString());28             decimal upperLimit = decimal.Parse(dtResult.Rows[j]["MAX_LIMIT"].ToString());29             decimal resultData = decimal.Parse(dtResult.Rows[j]["RESULTVALUE"].ToString());30             dr["MIN_LIMIT"] = lowerLimit;31             dr["MAX_LIMIT"] = upperLimit;32             dr["RESULTVALUE"] = resultData;33             dr["batch_name"] = dtResult.Rows[j]["batch_name"].ToString();34             dr["component_name"] = dtResult.Rows[j]["component_name"].ToString();35             if (resultData > upperLimit)36             {37                 this.chAnalysis.Series["ResultData"].Points[j].MarkerColor = Color.Red;38                 newdt.Rows.Add(dr);39             }40             if (resultData < lowerLimit)41             {42                 this.chAnalysis.Series["ResultData"].Points[j].MarkerColor = Color.Red;43                 newdt.Rows.Add(dr);44             }45         }46         chAnalysis.Titles.Add("检测项目质量回顾分析");47         DataView dv = dtResult.DefaultView;48         dv.Sort = "RESULTVALUE desc";49         double step = Math.Round((double.Parse(dv[0]["RESULTVALUE"].ToString()) - double.Parse(dv[dv.Count - 1]["RESULTVALUE"].ToString())) / 4, 1);50         double min = double.Parse(dv[dv.Count - 1]["RESULTVALUE"].ToString());51         chAnalysis.ChartAreas[0].AxisY.Maximum = (double)(double.Parse(dv[0]["RESULTVALUE"].ToString()) + step);52         chAnalysis.ChartAreas[0].AxisY.Minimum = min - step <= 0 ? 0 : min - step;53         chAnalysis.ChartAreas[0].AxisY.Interval = step;54         chAnalysis.ChartAreas[0].AxisX.Interval = 1;55         this.GridView1.DataSource = newdt;56         this.GridView1.DataBind();57     }

 

转载地址:http://ebzja.baihongyu.com/

你可能感兴趣的文章
Kali-linux Arpspoof工具
查看>>
PDF文档页面如何重新排版?
查看>>
基于http协议使用protobuf进行前后端交互
查看>>
UML设计一个电影票务销售系统(四)
查看>>
AlphaGo Zero用它来调参?【高斯过程】到底有何过人之处?
查看>>
Linux平台Oracle多个实例启动说明
查看>>
bash腳本編程之三 条件判断及算数运算
查看>>
php cookie
查看>>
linux下redis安装
查看>>
弃 Java 而使用 Kotlin 的你后悔了吗?| kotlin将会是最好的开发语言
查看>>
JavaScript 数据类型
查看>>
量子通信和大数据最有市场突破前景
查看>>
StringBuilder用法小结
查看>>
UVa 10252-Common Permutation
查看>>
CSS - 修改input - placeholder 和 readonly 的样式
查看>>
android studio :cannot resolve symbol R
查看>>
paper 20 :color moments
查看>>
代码大全
查看>>
博客园作业4--数组
查看>>
DataTable.ImportRow()与DataTable.Rows.Add()的区别
查看>>