Chart for WinRT > Chart Types > Candle Chart > Determining the Y-Coordinates of a Candle's High and Low Points |
If you need to display annotations just above the high point or just below the low point of a candle, use the following code:
C# |
Copy Code
|
---|---|
var ds = new HighLowOpenCloseSeries() { Label = "s1" }; ds.SymbolStrokeThickness = 3; ds.SymbolSize = new Size(20, 20); ds.XValuesSource = new DateTime[] { new DateTime(2008,10,1), new DateTime(2008,10,2), new DateTime(2008,10,3), new DateTime(2008,10,6), new DateTime(2008,10,7), new DateTime(2008,10,8) }; ds.OpenValuesSource = new double[] { 100, 102, 104, 100, 107, 102 }; ds.CloseValuesSource = new double[] { 102, 104, 100, 107, 102, 100 }; ds.HighValuesSource = new double[] { 102, 105, 105, 108, 109, 105 }; ds.LowValuesSource = new double[] { 99, 95, 95, 100, 96, 99, 98 }; ds.PlotElementLoaded += new EventHandler(ds_PlotElementLoaded); c1Chart1.Data.Children.Add(ds); c1Chart1.ChartType = ChartType.Candle; } void ds_PlotElementLoaded(object sender, EventArgs e) { var pe = (PlotElement)sender; // main canvas var cnv = pe.Parent as Canvas; // get data coordinates var x = (DateTime)pe.DataPoint["XValues"]; var high = (double)pe.DataPoint["HighValues"]; var low = (double)pe.DataPoint["LowValues"]; // convert to pixel coordinates var pthigh = c1Chart1.View.PointFromData(new Point(x.ToOADate(), high)); var ptlow = c1Chart1.View.PointFromData(new Point(x.ToOADate(), low)); // add labels cnv.Children.Add(CreateLabel(pthigh, high.ToString())); cnv.Children.Add(CreateLabel(ptlow, low.ToString())); } TextBlock CreateLabel(Point pt, string text) { var tb = new TextBlock() { Text = text }; Canvas.SetLeft(tb, pt.X); Canvas.SetTop(tb, pt.Y); return tb; } |