RWWithChartBar.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Sunny.UI;
  2. using System.Data;
  3. namespace WWPipeLine.MapBasic.Results
  4. {
  5. public class RWWithChartBar : RWWithChart
  6. {
  7. protected override void AddOptionSeries(DataTable dt)
  8. {
  9. foreach (DataRow dr in dt.Rows)
  10. {
  11. var color = m_Colors[dt.Rows.IndexOf(dr)];
  12. var series = new UIBarSeries
  13. {
  14. Name = dr[0].ToString()
  15. };
  16. for (int i = 1; i < dr.ItemArray.Length; i++)
  17. {
  18. double.TryParse(dr[i].ToString(), out double val);
  19. series.AddData(val, color);
  20. }
  21. ((UIBarOption)m_UIOption).AddSeries(series);
  22. }
  23. }
  24. protected override void AddXAxis(DataTable dt)
  25. {
  26. var option = m_UIOption as UIBarOption;
  27. option.XAxis.Scale = true;
  28. option.XAxis.MaxAuto = true;
  29. option.XAxis.MinAuto = true;
  30. var colIndex = 0;
  31. foreach (DataColumn colum in dt.Columns)
  32. {
  33. if (colIndex++ == 0) continue;
  34. option.XAxis.Data.Add(colum.ColumnName);
  35. }
  36. if (option.XAxis.Data.Count > 5)
  37. {
  38. option.XAxis.AxisLabel.Angle = 45;
  39. }
  40. else
  41. {
  42. option.XAxis.AxisLabel.Angle = 0;
  43. }
  44. }
  45. protected override void SetLegendItem(DataTable dt)
  46. {
  47. foreach (DataRow dr in dt.Rows)
  48. {
  49. ((UIBarOption)m_UIOption).Legend.AddData(dr[0].ToString(), m_Colors[dt.Rows.IndexOf(dr)]);
  50. }
  51. }
  52. protected override void CreateChart()
  53. {
  54. this.m_UIChart = new UIBarChart();
  55. m_UIOption = new UIBarOption();
  56. }
  57. protected override void SetOptionEx()
  58. {
  59. ((UIBarOption)m_UIOption).XAxis.Name = SetXAxisName();
  60. ((UIBarOption)m_UIOption).YAxis.Name = SetYAxisName();
  61. ((UIBarOption)m_UIOption).Grid.Left = 80;
  62. }
  63. }
  64. }