Advertisement
perjespersson

LABELS

Oct 28th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Windows.Forms.DataVisualization.Charting;
  11.  
  12. namespace WindowsFormsApp4
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. chart1.ChartAreas[0].AxisY.Maximum = 10;
  20. chart1.ChartAreas[0].AxisY.Interval = (10 / 10) * 2;
  21. chart1.ChartAreas[0].AxisY2.Maximum = 10;
  22. chart1.ChartAreas[0].AxisY2.Interval = (10 / 10) * 2;
  23. chart1.ChartAreas[0].AxisY2.LabelStyle.Enabled = false;
  24. chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
  25. }
  26.  
  27. private void Add_Click(object sender, EventArgs e)
  28. {
  29. chart1.Series[0].Points.AddXY(DateTime.Now.ToString("HH:mm:ss"), PointBox.Text.Replace(',','.'));
  30.  
  31. if (Convert.ToDouble(PointBox.Text) > chart1.ChartAreas[0].AxisY.Maximum)
  32. {
  33. double tal = Math.Ceiling(Convert.ToDouble(PointBox.Text));
  34. chart1.ChartAreas[0].AxisY.Maximum = tal;
  35. chart1.ChartAreas[0].AxisY.Interval = (tal / 10) * 2;
  36. chart1.ChartAreas[0].AxisY2.Maximum = tal;
  37. chart1.ChartAreas[0].AxisY2.Interval = (tal / 10) * 2;
  38.  
  39. }
  40. }
  41.  
  42. private void LeakButton_Click(object sender, EventArgs e)
  43. {
  44. chart1.ChartAreas[0].AxisY2.LabelStyle.Enabled = true;
  45. chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = true;
  46. chart1.ChartAreas[0].AxisY2.CustomLabels.Clear();
  47. Double CustomOne = -1;
  48. Double CustomTwo = -1;
  49.  
  50. try
  51. {
  52. CustomOne = Convert.ToDouble(LeakOne.Text);
  53. }
  54.  
  55. catch (System.FormatException)
  56. {
  57. }
  58.  
  59. try
  60. {
  61. CustomTwo = Convert.ToDouble(LeakTwo.Text);
  62. }
  63.  
  64. catch (System.FormatException)
  65. {
  66. }
  67.  
  68. CustomLabel Leak1 = new CustomLabel
  69. {
  70. FromPosition = CustomOne+0.5,
  71. ToPosition = CustomOne-0.5,
  72. ForeColor = Color.Green,
  73. Text = "Leak A",
  74. GridTicks = System.Windows.Forms.DataVisualization.Charting.GridTickTypes.Gridline
  75. };
  76. chart1.ChartAreas[0].AxisY2.CustomLabels.Add(Leak1);
  77.  
  78. CustomLabel Leak2 = new CustomLabel
  79. {
  80. FromPosition = CustomTwo+0.5,
  81. ToPosition = CustomTwo-0.5,
  82. ForeColor = Color.Red,
  83. Text = "Leak B",
  84. GridTicks = System.Windows.Forms.DataVisualization.Charting.GridTickTypes.Gridline
  85. };
  86.  
  87. chart1.ChartAreas[0].AxisY2.CustomLabels.Add(Leak2);
  88.  
  89.  
  90.  
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement