C#图表垂直文本注释(c# chart vertical text annotation)

2019-09-22 09:15发布

我添加批注AC#线图。 我想改变文字的方向,但不能看到任何设置,以允许此。

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);

注释被添加到正确的图形和矩形和文字从左到右。 我想定向它跑上跑下。 任何建议如何实现这一目标?

Answer 1:

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

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。 基本上你需要使用e.Graphics.RotateTransform(270); 属性(即线将旋转270度)。



文章来源: c# chart vertical text annotation
标签: c# charts