0

Im wondering if its possible to add colored triangles (pointing up or down) at specific points (x,y) on an existing chart, such that they will update their positions if the chart is scrolled/zoomed.

Ive had a google around but havent stumbled across anything which seems to meet those requirements.

Any pointers would be appreciated.

leppie
  • 115,091
  • 17
  • 196
  • 297
Hans Rudel
  • 3,433
  • 5
  • 39
  • 62
  • 1
    Cant you just use markers on datapoints ? – Quantbuff Nov 07 '12 at 17:48
  • Yeah that seems to be what im looking for. Its a candle stick chart though and im not sure how to specify what the Y axis value should be as its currently just placing a dot at the low. Any ideas? – Hans Rudel Nov 09 '12 at 14:02
  • 1
    DO you know the XValue,Yvalue where you want to show that rectangle ? If Yes then you can just draw a point chart with markers – Quantbuff Nov 09 '12 at 16:01
  • Yeah i got it working (i think), thanks very much for your help. One final question, do u know if its possible to invert the triangle ie so its pointing down? – Hans Rudel Nov 09 '12 at 16:59
  • 1
    for that you can create your own image and use MarkerImage property to load custom image. Here you go http://stackoverflow.com/questions/6682404/custom-markerstyles-possible-in-microsoft-chart-controls – Quantbuff Nov 09 '12 at 21:32
  • Thanks very much QuantBuff, much appreciated. (If u want some extra rep points, put the above comments into a ans and ill mark it as accepted.) – Hans Rudel Nov 10 '12 at 10:23

2 Answers2

2

As described inside the MS Chart Samples, you could probably use annotations for this

private void AddLineAnnotation()
{
 LineAnnotation annotation = new LineAnnotation();
 annotation.AnchorDataPoint = Chart1.Series[0].Points[2];
 annotation.Height = -25;
 annotation.Width = -25;
 annotation.LineWidth = 2;
 annotation.StartCap = LineAnchorCapStyle.Arrow;
 annotation.EndCap = LineAnchorCapStyle.Arrow;
 Chart1.Annotations.Add(annotation);
}

You can even define a custom polygon as annotation

private void AddPolygonAnnotation()
{
 PolygonAnnotation annotation = new PolygonAnnotation();
 annotation.AnchorDataPoint = Chart1.Series[0].Points[2];

 // explicitly set the relative height and width
 annotation.Height = 50;
 annotation.Width = 30;

 annotation.BackColor = Color.FromArgb(128, Color.Orange);
 annotation.LineColor = Color.Black;
 annotation.LineDashStyle = ChartDashStyle.Solid;

 // define relative value points for a polygon
 PointF [] points = new PointF[5];
 points[0].X = 0;
 points[0].Y = 0;                
 points[1].X = 100;
 points[1].Y = 0;       
 points[2].X = 100;
 points[2].Y = 100;        
 points[3].X = 0;
 points[3].Y = 100;       
 points[4].X = 50;
 points[4].Y = 50;

 annotation.Path.AddPolygon(points);      
 Chart1.Annotations.Add(annotation);
}
zeFrenchy
  • 6,541
  • 1
  • 27
  • 36
  • 1
    I tried the code you supplied regarding Polygons but i couldnt get it to work. From what ive managed to see, Markers are what im looking for. Any idea on how i can specify the X and Y value for them? Thanks for your time. – Hans Rudel Nov 09 '12 at 14:29
2

Draw a point chart with markers. Create your own image and use MarkerImage property to load custom image

Answer Explaining how to get your inverted triangles Custom MarkerStyles possible in Microsoft Chart Controls?

Community
  • 1
  • 1
Quantbuff
  • 827
  • 7
  • 9