DEVChart_ParticlesComposition.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. using DevExpress.Charts.Model;
  2. using DevExpress.Utils;
  3. using DevExpress.XtraCharts;
  4. using DevExpress.XtraReports.UI;
  5. using NPOI.Util;
  6. using OTSIncAReportApp._1_UI.Control_DEVCharts;
  7. using OTSIncAReportApp.DataOperation.DataAccess;
  8. using OTSIncAReportApp.OTSRstMgrFunction;
  9. using OTSIncAReportApp.OTSSampleReportInfo;
  10. using OTSIncAReportApp.SysMgrTools;
  11. using OTSIncAReportGrids;
  12. using System;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Windows.Forms;
  19. using System.Xml;
  20. using static System.Net.WebRequestMethods;
  21. namespace OTSIncAReportApp.Control_ECharts
  22. {
  23. /// <summary>
  24. /// 各图char相关模块
  25. /// </summary>
  26. public partial class DEVChart_ParticlesComposition : UserControl
  27. {
  28. Hashtable table;
  29. #region 图表相关变量
  30. //y轴名称
  31. public string m_str_AxisY { get; set; }
  32. //数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize
  33. string ComSel { get; set; }
  34. public bool Report { get; set; }
  35. frmReportApp m_ReportApp;
  36. private frmReportConditionChoose m_conditionChoose;
  37. private ResultDataMgr m_DataMgr;
  38. private List<DataTable> prListData = new List<DataTable>();
  39. private List<string> prListString = new List<string>();
  40. #endregion
  41. #region 窗体加载及构造函数
  42. public DEVChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
  43. {
  44. ComSel = comsel;
  45. m_ReportApp = ReportApp;
  46. m_conditionChoose = ReportApp.m_conditionChoose;
  47. m_DataMgr = ReportApp.m_rstDataMgr;
  48. InitializeComponent();
  49. //国际化
  50. Language lan = new Language();
  51. table = lan.GetNameTable("CompositionDistributionGrid");
  52. comboBox1.SelectedIndex = 0;
  53. }
  54. private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
  55. {
  56. string sou = "";
  57. int sel = 0;//选择颗粒范围(0为全部颗粒1为选择颗粒)
  58. if (Report)
  59. {
  60. sou = m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResultId()].anotherFileName.ToString();
  61. sel = 0;
  62. }
  63. else
  64. {
  65. sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  66. sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  67. }
  68. Report = false;
  69. if (m_ReportApp.more)
  70. {
  71. m_ReportApp.trans = false;
  72. }
  73. else
  74. {
  75. m_ReportApp.trans = true;
  76. }
  77. m_ReportApp.more = true;
  78. List<DataTable> list_dt = GetListJsonStr();
  79. bool bl = false;
  80. for (int i=0;i< list_dt.Count;i++)
  81. {
  82. if (list_dt[i].Rows.Count>0)
  83. {
  84. bl = true;
  85. }
  86. }
  87. List<DataTable> listDt = new List<DataTable>();
  88. for (int i=0;i< list_dt.Count;i++)
  89. {
  90. DataTable dt = list_dt[i].Clone();
  91. for (int a=0;a< list_dt[i].Rows.Count;a++)
  92. {
  93. if (list_dt[i].Rows[a]["name"].ToString() != "")
  94. {
  95. dt.Rows.Add(list_dt[i].Rows[a].ItemArray);
  96. }
  97. }
  98. listDt.Add(dt);
  99. }
  100. prListData = listDt.Copy();
  101. prListString.Clear();
  102. for (int i = 0; i < list_dt.Count; i++)
  103. {
  104. ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  105. string str = resultFile.anotherFileName;
  106. prListString.Add(str);
  107. }
  108. panel1.Dock = DockStyle.Fill;
  109. chartControl1.Dock = DockStyle.Fill;
  110. int sel_pro = m_conditionChoose.m_conditionData.ProItemProIndex();
  111. if (sel_pro == 2)
  112. {
  113. comboBox1.Visible = false;
  114. Graphics_Stacking(list_dt[0]);
  115. }
  116. else
  117. {
  118. comboBox1.Visible = true;
  119. Graphics();
  120. }
  121. }
  122. #endregion
  123. #region 获取单数据源
  124. private DataTable ClassificationIntegration(string path, int sel)
  125. {
  126. //------------------加载模块,获取数据-------------------------------------------------
  127. ResultGrid ls_resultgrid = new ResultGrid(m_ReportApp);
  128. Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid_Report();
  129. //------------------加载模块,获取数据结束----------------------------------------------
  130. Dictionary<string, string>.Enumerator en = keyValues_ResultGrid.GetEnumerator();
  131. string str_SCZS = "";
  132. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
  133. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  134. DataTable data = new DataTable();
  135. data = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
  136. if (data.Rows.Count == 0)
  137. {
  138. return data;
  139. }
  140. DataTable AreaInformationOfAllElements = ConSolidateInvalid(data);
  141. DataTable AllAnalysisDetails = new DataTable();
  142. AllAnalysisDetails.Columns.Add("Name");
  143. AllAnalysisDetails.Columns.Add("TypeId");
  144. AllAnalysisDetails.Columns.Add("Area", typeof(double));
  145. AllAnalysisDetails.Columns.Add("Class");
  146. AllAnalysisDetails.Columns.Add("Cunt", typeof(double));
  147. for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++)
  148. {
  149. DataRow dr2 = AllAnalysisDetails.NewRow();
  150. dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString();
  151. dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]);
  152. dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString();
  153. dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]);
  154. dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString();
  155. AllAnalysisDetails.Rows.Add(dr2);
  156. }
  157. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  158. List<string> ClassName = new List<string>();
  159. DataTable getClass_dt = particledata.GetAllClass();
  160. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  161. {
  162. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  163. }
  164. DataTable AreaRatio = new DataTable();
  165. AreaRatio.TableName = "InclusionAreaRatio";
  166. AreaRatio.Columns.Add("e1");
  167. AreaRatio.Columns.Add("e2");
  168. AreaRatio.Columns.Add("e3", typeof(double));
  169. AreaRatio.Columns.Add("e4");
  170. AreaRatio.Columns.Add("e5");
  171. AreaRatio.Columns.Add("Cunt", typeof(int));
  172. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  173. double totalInclusionArea = 0;
  174. totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString()));
  175. for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++)
  176. {
  177. DataRow dr2 = AreaRatio.NewRow();
  178. dr2["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString();
  179. dr2["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString();
  180. dr2["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]);
  181. dr2["e4"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2);
  182. dr2["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  183. dr2["Cunt"] = AllAnalysisDetails.Rows[i]["Cunt"].ToString();
  184. AreaRatio.Rows.Add(dr2);
  185. }
  186. DataTable AreaRatio_dt = AreaRatio.Copy();
  187. AreaRatio_dt.Clear();
  188. for (int i = 0; i < ClassName.Count(); i++)
  189. {
  190. DataTable dt = AreaRatio.Copy();
  191. dt.Clear();
  192. for (int a = 0; a < AreaRatio.Rows.Count; a++)
  193. {
  194. if (AreaRatio.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  195. {
  196. dt.Rows.Add(AreaRatio.Rows[a].ItemArray);
  197. }
  198. }
  199. DataView dv = dt.DefaultView;
  200. dv.Sort = "e3 DESC";
  201. DataTable dt_Element = dv.ToTable();
  202. for (int a = 0; a < dt_Element.Rows.Count; a++)
  203. {
  204. AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
  205. }
  206. }
  207. DataTable AllAnalysisDetails1 = AreaRatio_dt.Copy();
  208. AllAnalysisDetails1.Clear();
  209. for (int i = 0; i < ClassName.Count; i++)
  210. {
  211. DataTable dt = AreaRatio_dt.Copy();
  212. dt.Clear();
  213. for (int a = 0; a < AreaRatio_dt.Rows.Count; a++)
  214. {
  215. if (AreaRatio_dt.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  216. {
  217. dt.Rows.Add(AreaRatio_dt.Rows[a].ItemArray);
  218. }
  219. }
  220. if (dt.Rows.Count > 0)
  221. {
  222. double totalInclusionArea2 = Convert.ToDouble(decimal.Parse(AreaRatio_dt.Compute("sum(e3)", "").ToString()));
  223. double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  224. int cunt = Convert.ToInt32(decimal.Parse(dt.Compute("sum(Cunt)", "").ToString()));
  225. DataRow dr3 = AllAnalysisDetails1.NewRow();
  226. dr3["e1"] = ClassName[i].ToString();
  227. dr3["e3"] = Math.Round(Area, 2);
  228. dr3["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea2) * 100, 2);
  229. dr3["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  230. dr3["Cunt"] = cunt;
  231. AllAnalysisDetails1.Rows.Add(dr3);
  232. }
  233. }
  234. return AllAnalysisDetails1;
  235. }
  236. private DataTable ConSolidateInvalid(DataTable dt)
  237. {
  238. DataTable dt_invalid = dt.Clone();
  239. DataTable dt_no_invalid = dt.Clone();
  240. for (int i = 0; i < dt.Rows.Count; i++)
  241. {
  242. if (dt.Rows[i]["TypeName"].ToString() == "Invalid")
  243. {
  244. dt_invalid.Rows.Add(dt.Rows[i].ItemArray);
  245. }
  246. else
  247. {
  248. dt_no_invalid.Rows.Add(dt.Rows[i].ItemArray);
  249. }
  250. }
  251. return dt_no_invalid;
  252. }
  253. private string getWhere(string max, string min, string col)
  254. {
  255. if (col == "Area")
  256. {
  257. return col + ">=" + ((Convert.ToDouble(min) / 2) * (Convert.ToDouble(min) / 2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max) / 2) * (Convert.ToDouble(max) / 2) * Math.PI).ToString();
  258. }
  259. else
  260. {
  261. return col + ">=" + min + " and " + col + "<" + max;
  262. }
  263. }
  264. #endregion
  265. #region echarts
  266. /// <summary>
  267. /// 通过m_list_chartstruct,组合json数据格式
  268. /// </summary>
  269. /// <returns></returns>
  270. private List<DataTable> GetListJsonStr()
  271. {
  272. int sel = m_conditionChoose.m_conditionData.ProItemProIndex();
  273. string filedAndParticl = "";
  274. DataOperation.DataAccess.ParticleData particledata = null;
  275. DataTable dt = new DataTable();
  276. List<DataTable> ListData = new List<DataTable>();
  277. string sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  278. for (int i = 0; i < sou.Split('+').Length; i++)
  279. {
  280. ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  281. if (resultFile == null)
  282. {
  283. continue;
  284. }
  285. particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
  286. switch (ComSel)
  287. {
  288. case "InclusionareaRatio":
  289. dt = particledata.GetAreaByAllIncA("");
  290. DataTable dtInclusionareaRatio = new DataTable();
  291. dtInclusionareaRatio.Columns.Add("name");
  292. dtInclusionareaRatio.Columns.Add("Cunt");
  293. for (int k = 0; k < dt.Rows.Count; k++)
  294. {
  295. string str = dt.Rows[k]["ar"].ToString();
  296. string name = dt.Rows[k]["TypeName"].ToString();
  297. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  298. {
  299. continue;
  300. }
  301. DataRow dr = dtInclusionareaRatio.NewRow();
  302. dr["name"] = name;
  303. dr["Cunt"] = decimal.Round(decimal.Parse(dt.Rows[k]["ar"].ToString()), 2).ToString();
  304. dtInclusionareaRatio.Rows.Add(dr);
  305. }
  306. ListData.Add(dtInclusionareaRatio);
  307. break;
  308. case "CommonlyUsedClassify":
  309. //计算分类整个表的数据
  310. dt = ClassificationIntegration(resultFile.FilePath, sel);
  311. DataTable data = new DataTable();
  312. data.Columns.Add("name");
  313. data.Columns.Add("Cunt");
  314. for (int a = 0; a < dt.Rows.Count; a++)
  315. {
  316. DataRow dr = data.NewRow();
  317. dr["name"] = dt.Rows[a]["e1"].ToString();
  318. dr["Cunt"] = dt.Rows[a]["Cunt"].ToString();
  319. data.Rows.Add(dr);
  320. }
  321. ListData.Add(data);
  322. break;
  323. case "PComponent":
  324. //创建新的图形数据源
  325. dt = particledata.GetParticleListByIncA("area");
  326. DataTable dtPComponent = new DataTable();
  327. dtPComponent.Columns.Add("name");
  328. dtPComponent.Columns.Add("Cunt");
  329. for (int a = 0; a < dt.Rows.Count; a++)
  330. {
  331. if (Convert.ToInt32(dt.Rows[a]["TypeId"]) < 100)
  332. {
  333. continue;
  334. }
  335. DataRow dr = dtPComponent.NewRow();
  336. dr["name"] = dt.Rows[a]["TypeName"].ToString();
  337. dr["Cunt"] = dt.Rows[a]["con"].ToString();
  338. dtPComponent.Rows.Add(dr);
  339. }
  340. ListData.Add(dtPComponent);
  341. break;
  342. case "EComponent":
  343. //创建新的图形数据源
  344. dt = particledata.GetElementForArea(filedAndParticl);
  345. DataTable dtEComponent = new DataTable();
  346. dtEComponent.Columns.Add("name");
  347. dtEComponent.Columns.Add("Cunt");
  348. for (int k = 0; k < dt.Rows.Count; k++)
  349. {
  350. string str = dt.Rows[k]["earea"].ToString();
  351. try
  352. {
  353. DataRow dr = dtEComponent.NewRow();
  354. dr["name"] = dt.Rows[k]["name"].ToString();
  355. dr["Cunt"] = decimal.Round(decimal.Parse(str), 2).ToString();
  356. dtEComponent.Rows.Add(dr);
  357. }
  358. catch
  359. {
  360. DataRow dr = dtEComponent.NewRow();
  361. dr["name"] = dt.Rows[k]["name"].ToString();
  362. dr["Cunt"] = str;
  363. dtEComponent.Rows.Add(dr);
  364. }
  365. }
  366. ListData.Add(dtEComponent);
  367. break;
  368. case "PSize":
  369. //获取粒级表
  370. string pathe = m_DataMgr.m_RptConfigFile.PartSizeFileFolder + m_DataMgr.m_RptConfigFile.PartSizeFile;
  371. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  372. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  373. List<string> temp = new List<string>();
  374. for (int j = 0; j < sizestr.Split(',').Length - 1; j++)
  375. {
  376. if (sizestr.Split(',')[j].Length > 0)
  377. {
  378. double d1 = Convert.ToDouble(sizestr.Split(',')[j]);
  379. double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]);
  380. string name = d1.ToString() + "~" + d2.ToString();
  381. temp.Add(name);
  382. }
  383. }
  384. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  385. string name1 = d.ToString() + "~MAX";
  386. temp.Add(name1);
  387. string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  388. string po = "";
  389. switch (con)
  390. {
  391. case "DMAX":
  392. po = "DMAX";
  393. break;
  394. case "DMIN":
  395. po = "DMIN";
  396. break;
  397. case "ECD":
  398. po = "Area";
  399. break;
  400. case "FERET":
  401. po = "DFERET";
  402. break;
  403. }
  404. var dpd= DataProcessing(particledata,po, temp);
  405. ListData.Add(dpd);
  406. break;
  407. }
  408. }
  409. return ListData;
  410. }
  411. private DataTable DataProcessing(ParticleData particledata,string po, List<string> temp)
  412. {
  413. DataTable pos_dt = particledata.GetParticleListForParticlSize("area", "");
  414. DataTable pos_AreaInformationOfAllElements = particledata.GetAreaByAllIncA("");
  415. DataTable pos_dtp = particledata.GetParticleAll("");
  416. List<string> colid = new List<string>() { "name", "ar", "TypeId", "Largest", "Class", "GroupId", "con" };
  417. DataTable m_bt_DBData = new DataTable();
  418. for (int i = 0; i < temp.Count; i++)
  419. {
  420. colid.Add(temp[i].ToString());
  421. }
  422. for (int i = 0; i < colid.Count; i++)
  423. {
  424. m_bt_DBData.Columns.Add(colid[i].ToString());
  425. }
  426. for (int i = 0; i < pos_dt.Rows.Count; i++)
  427. {
  428. DataRow dr = m_bt_DBData.NewRow();
  429. dr["name"] = pos_dt.Rows[i]["TypeName"].ToString();
  430. dr["TypeId"] = pos_dt.Rows[i]["TypeId"].ToString();
  431. dr["con"] = pos_dt.Rows[i]["con"].ToString();
  432. dr["GroupId"] = pos_dt.Rows[i]["GroupId"].ToString();
  433. if (pos_dt.Rows[i]["GroupName"].ToString() == "")
  434. dr["Class"] = "Default";
  435. else
  436. dr["Class"] = pos_dt.Rows[i]["GroupName"].ToString();
  437. //continue;
  438. dr["Largest"] = Math.Round(Convert.ToDouble(pos_dt.Rows[i]["max"]), 2);
  439. for (int a = 7; a < colid.Count; a++)
  440. {
  441. string d1 = colid[a].Split('~')[0];
  442. string d2 = colid[a].Split('~')[1];
  443. if (d2 == "MAX")
  444. {
  445. d2 = "999";
  446. }
  447. DataRow[] datas = pos_dtp.Select(getWhere(d2, d1, po, pos_dt.Rows[i]["TypeId"].ToString()));
  448. dr[colid[a]] = datas.Count();
  449. }
  450. for (int a = 0; a < pos_AreaInformationOfAllElements.Rows.Count; a++)
  451. {
  452. if (pos_dt.Rows[i]["TypeId"].ToString() == pos_AreaInformationOfAllElements.Rows[a]["TypeId"].ToString())
  453. {
  454. dr["ar"] = pos_AreaInformationOfAllElements.Rows[a]["ar"];
  455. }
  456. }
  457. m_bt_DBData.Rows.Add(dr);
  458. }
  459. return m_bt_DBData;
  460. }
  461. private string getWhere(string max, string min, string col, string partic)
  462. {
  463. if (col == "Area")
  464. {
  465. return col + ">=" + ((Convert.ToDouble(min) / 2) * (Convert.ToDouble(min) / 2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max) / 2) * (Convert.ToDouble(max) / 2) * Math.PI).ToString() + " and TypeId=" + partic;
  466. }
  467. else
  468. {
  469. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  470. }
  471. }
  472. #endregion
  473. private void Graphics_Stacking(DataTable dt)
  474. {
  475. chartControl1.Series.Clear();
  476. List<Series> seriesList = new List<Series>();
  477. DataTable data = new DataTable();
  478. data.Columns.Add("name");
  479. data.Columns.Add("range");
  480. data.Columns.Add("num");
  481. for (int i = 0; i < dt.Rows.Count; i++)
  482. {
  483. for (int a = 7; a < dt.Columns.Count; a++)
  484. {
  485. DataRow dr = data.NewRow();
  486. dr["name"] = dt.Rows[i]["name"].ToString();
  487. dr["range"] = dt.Columns[a].ColumnName;
  488. dr["num"] = dt.Rows[i][a].ToString();
  489. data.Rows.Add(dr);
  490. }
  491. }
  492. foreach (DataRow dr in data.DefaultView.ToTable(true, "name").Rows)
  493. {
  494. Series s = new Series(dr["name"].ToString(), ViewType.StackedBar)
  495. {
  496. LegendTextPattern = dr["name"].ToString(),
  497. ArgumentScaleType = ScaleType.Qualitative,
  498. };
  499. foreach (DataRow drl in data.Select("name='" + dr["name"].ToString() + "'"))
  500. s.Points.Add(new SeriesPoint(drl["range"].ToString(), int.Parse(drl["num"].ToString())));
  501. s.LabelsVisibility = DefaultBoolean.False;
  502. seriesList.Add(s);
  503. }
  504. foreach (DataRow dr in data.DefaultView.ToTable(true, "name").Rows)
  505. {
  506. Series s = new Series(dr["name"].ToString(), ViewType.StackedBar)
  507. {
  508. LegendTextPattern = dr["name"].ToString(),
  509. ArgumentScaleType = ScaleType.Qualitative,
  510. };
  511. foreach (DataRow drl in data.Select("name='" + dr["name"].ToString() + "'"))
  512. s.Points.Add(new SeriesPoint(drl["range"].ToString(), int.Parse(drl["num"].ToString())));
  513. s.LabelsVisibility = DefaultBoolean.False;
  514. seriesList.Add(s);
  515. }
  516. foreach (Series sr in seriesList.ToArray())
  517. chartControl1.Series.Add(sr);
  518. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "";
  519. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Text = "";
  520. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visibility = DefaultBoolean.True;
  521. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Visibility = DefaultBoolean.True;
  522. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("Tahoma", 9);
  523. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Font = new Font("Tahoma", 9);
  524. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Alignment = System.Drawing.StringAlignment.Far;
  525. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Alignment = System.Drawing.StringAlignment.Far;
  526. //图例的位置定义
  527. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  528. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  529. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  530. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  531. //十字准线光标
  532. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  533. chartControl1.CrosshairOptions.ShowValueLine = true;
  534. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  535. }
  536. private void Graphics()
  537. {
  538. chartControl1.Series.Clear();
  539. for (int i = 0; i < prListData.Count; i++)
  540. {
  541. string str = prListString[i];
  542. // 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
  543. Series series = new Series(str, ViewType.Bar);
  544. for (int a = 0; a < prListData[i].Rows.Count; a++)
  545. {
  546. string name = prListData[i].Rows[a]["name"].ToString();
  547. double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
  548. series.Points.Add(new SeriesPoint(name, Cunt));
  549. }
  550. series.LabelsVisibility = DefaultBoolean.True;
  551. chartControl1.Series.Add(series);
  552. }
  553. //图例的位置定义
  554. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  555. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  556. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  557. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  558. //十字准线光标
  559. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  560. chartControl1.CrosshairOptions.ShowValueLine = true;
  561. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  562. DevFunctions.ChangeView2(chartControl1, comboBox1.Text);
  563. }
  564. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  565. {
  566. Graphics();
  567. }
  568. }
  569. }