2012-09-13 31 views
4

我将注释添加到c#折线图。我想改变文字方向,但看不到任何设置以允许这样做。c#图表垂直文本注释

RectangleAnnotationannotation = new RectangleAnnotation(); 
annotation.AnchorDataPoint = chart1.Series[0].Points[x]; 
annotation.Text = "look an annotation"; 
annotation.ForeColor = Color.Black; 
annotation.Font = new Font("Arial", 12); ; 
annotation.LineWidth = 2; 
chart1.Annotations.Add(annotation); 

将注释正确添加到图形中,矩形和文本从左向右运行。我想定位它来上下运行。有关如何实现这一目标的任何建议?

+1

我很好奇,如果你曾经找到这个问题的解决方案,或者如果你有它的工作。 – tmwoods

回答

0

您不能使用注释库来旋转注释。您必须使用postpaintprepaintHere是如何使用后期事件的一个很好的例子。希望这可以帮助。我会包括来自下面的链接代码:

protected void Chart1_PostPaint(object sender, ChartPaintEventArgs e) 
{ 
if (e.ChartElement is Chart) 
{ 
    // create text to draw 
    String TextToDraw; 
    TextToDraw = "Printed: " + DateTime.Now.ToString("MMM d, yyyy @ h:mm tt"); 
    TextToDraw += " -- Copyright © Steve Wellens"; 

    // get graphics tools 
    Graphics g = e.ChartGraphics.Graphics; 
    Font DrawFont = System.Drawing.SystemFonts.CaptionFont; 
    Brush DrawBrush = Brushes.Black; 

    // see how big the text will be 
    int TxtWidth = (int)g.MeasureString(TextToDraw, DrawFont).Width; 
    int TxtHeight = (int)g.MeasureString(TextToDraw, DrawFont).Height; 

    // where to draw 
    int x = 5; // a few pixels from the left border 

    int y = (int)e.Chart.Height.Value; 
    y = y - TxtHeight - 5; // a few pixels off the bottom 

    // draw the string   
    g.DrawString(TextToDraw, DrawFont, DrawBrush, x, y); 
} 

}

编辑:我只是意识到这个例子实际上不旋转文本。我知道你必须使用这个工具,所以我会尝试找到一个使用旋转文本的postpaint的例子。

编辑2:啊。 SO上的here。基本上你需要使用e.Graphics.RotateTransform(270);属性(该行将旋转270度)。

+0

不幸的是,除非你真的在Paint事件本身做到这一点,否则它似乎是不可能的! e.ChartGraphics.Graphics不适用于旋转 – TaW