Last active
August 29, 2015 14:17
-
-
Save bboyle1234/dee2a55bb24c2ade55c8 to your computer and use it in GitHub Desktop.
Example line plotting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Plotting methods | |
#region PlotLine | |
protected void PlotLine(Graphics graphics, Rectangle bounds, double min, double max, Pen pen, Func<int, double?> GetLineValueAtIndex) { | |
var firstBarIndex = ChartControl.FirstBarPainted; | |
var lastBarIndex = Math.Min(BarsArray[0].Count - 1, ChartControl.LastBarPainted); | |
using (var path = new GraphicsPath()) { | |
for (var barIndex = firstBarIndex; barIndex < lastBarIndex; barIndex++) { | |
var value1 = GetLineValueAtIndex(barIndex); | |
var value2 = GetLineValueAtIndex(barIndex + 1); | |
if (value1.HasValue && value2.HasValue) { | |
var x1 = ChartControl.GetXByBarIdx(BarsArray[0], barIndex); | |
var x2 = ChartControl.GetXByBarIdx(BarsArray[0], barIndex + 1); | |
var y1 = ChartControl.GetYByValue(BarsArray[0], value1.Value); | |
var y2 = ChartControl.GetYByValue(BarsArray[0], value2.Value); | |
path.AddLine(x1, y1, x2, y2); | |
} | |
} | |
graphics.DrawPath(pen, path); | |
} | |
#region demo code | |
//NinjaTrader.Gui.Chart.PlotStyle plotStyle = Gui.Chart.PlotStyle.Line; | |
//switch (plotStyle) { | |
// case NinjaTrader.Gui.Chart.PlotStyle.Line: { | |
// if (lastX >= 0) { | |
// if (graphicsPath == null) | |
// graphicsPath = new GraphicsPath(); | |
// int offset = (int)Math.Ceiling(drawPenWidth / 4); // this is a heuristic value to make style 'Line' math with style 'Bar' CH 20100624 | |
// graphicsPath.AddLine(lastX - offset, lastY, x - offset, y); | |
// } | |
// break; | |
// } | |
//} | |
#endregion | |
} | |
#endregion | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment