Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. DataTable table_ChartData = new DataTable();
  2. table_ChartData.Columns.Add("Id");
  3. table_ChartData.Columns.Add("Open");
  4. table_ChartData.Columns.Add("Close");
  5. table_ChartData.Columns.Add("High");
  6. table_ChartData.Columns.Add("Low");
  7. table_ChartData.Columns.Add("Day");
  8. dataGridView1.DataSource = table_ChartData;
  9.  
  10. chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
  11. chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
  12. chart1.ChartAreas["ChartArea1"].AxisY.Maximum = max;
  13. chart1.ChartAreas["ChartArea1"].AxisY.Minimum = min;
  14.  
  15. chart1.Series["Daily"].XValueMember = "Day";
  16. chart1.Series["Daily"].YValueMembers = "High,Low,Open,Close";
  17. chart1.Series["Daily"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
  18.  
  19. chart1.Series["Daily"].CustomProperties = "PriceDownColor=Blue,PriceUpColor=Red";
  20. chart1.Series["Daily"]["OpenCloseStyle"] = "Triangle";
  21. chart1.Series["Daily"]["ShowOpenClose"] = "Both";
  22.  
  23. chart1.DataSource = table_ChartData;
  24. chart1.DataBind();
  25.  
  26. private void chart1_MouseMove(object sender, MouseEventArgs e)
  27. {
  28.  
  29. Point mousePoint = new Point(e.X, e.Y);
  30. chart1.ChartAreas[0].CursorX.SetCursorPixelPosition(mousePoint, true);
  31. chart1.ChartAreas[0].CursorY.SetCursorPixelPosition(mousePoint, true);`
  32.  
  33. var pos = e.Location;
  34. if (prevPosition.HasValue && pos == prevPosition.Value)
  35. return;
  36. tooltip.RemoveAll();
  37. prevPosition = pos;
  38. var results = chart1.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint); // set ChartElementType.PlottingArea for full area, not only DataPoints
  39. foreach (var result in results)
  40. {
  41. if (result.ChartElementType == ChartElementType.DataPoint) // set ChartElementType.PlottingArea for full area, not only DataPoints
  42. {
  43. var yVal = result.ChartArea.AxisY.PixelPositionToValue(pos.Y);
  44. tooltip.Show(((int)yVal).ToString(), chart1, pos.X, pos.Y - 15);
  45. }
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement