4

我正在向 ac# 折线图添加注释。我想更改文本方向,但看不到任何允许这样做的设置。

RectangleAnnotation annotation = 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);

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

4

1 回答 1

0

您不能使用注释库旋转注释。您必须使用postpaintprepaint是一个如何使用 post-paint 事件的好例子。希望这可以帮助。我将包含以下链接中的代码:

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:啊。就在这里。基本上您需要使用该e.Graphics.RotateTransform(270);属性(该线将旋转 270 度)。

于 2013-02-27T18:31:46.453 回答