public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { DateTime time = new DateTime((long)Chart.stockPricePlot.PhysicalXAxis1Cache.PhysicalToWorld(new System.Drawing.Point(X, Y), false)); int idx = Chart.GetTimeIndex(time); if (idx >= 0) { float price = (float)Chart.Source.Rows[idx]["Price"]; Chart.priceText.Text = String.Format("{0:c}", price); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(Lines.Canvas.Image)) { PhysicalAxis xAxis = Chart.stockPricePlot.PhysicalXAxis1Cache; PhysicalAxis yAxis = Chart.stockPricePlot.PhysicalYAxis1Cache; g.Clear(System.Drawing.Color.Transparent); // Draw the time line System.Drawing.PointF timePoint = xAxis.WorldToPhysical(time.Ticks, true); g.DrawLine(Lines.TimePen, timePoint.X, yAxis.PhysicalMin.Y, timePoint.X, yAxis.PhysicalMax.Y); // Draw the guide lines System.Drawing.PointF minPoint = yAxis.WorldToPhysical(price / GuideLinePercentage, true); System.Drawing.PointF maxPoint = yAxis.WorldToPhysical(price * GuideLinePercentage, true); g.DrawLine(Lines.PricePen, xAxis.PhysicalMin.X, minPoint.Y, xAxis.PhysicalMax.X, minPoint.Y); g.DrawLine(Lines.PricePen, xAxis.PhysicalMin.X, maxPoint.Y, xAxis.PhysicalMax.X, maxPoint.Y); } // Use this as a hook to update the minimum and maximum displayed prices Chart.UpdatePriceMinMax(); // Refresh the canvas to display the updated lines Chart.stockPricePlot.Canvas.Refresh(); } return(false); }
/// <summary> /// Adds lines to the chart /// </summary> /// <param name="pen">The pen to draw with</param> /// <param name="lines">The lines to draw (start and end points)</param> public void AddLine(System.Drawing.Pen pen, float startX, float startY, float endX, float endY) { // Draw the line on the chart using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(Canvas.Image)) { PhysicalAxis xAxis = Chart.Plot.PhysicalXAxis1Cache; PhysicalAxis yAxis = Chart.Plot.PhysicalYAxis1Cache; // Draw the line if (xAxis != null && yAxis != null) { g.DrawLine(pen, xAxis.WorldToPhysical(startX, true).X, yAxis.WorldToPhysical(startY, true).Y, xAxis.WorldToPhysical(endX, true).X, yAxis.WorldToPhysical(endY, true).Y); } } }