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

注釈ライブラリを使用して注釈を回転させることはできません。postpaintまたはを使用する必要がありprepaintます。これは、ペイント後のイベントの使用方法の良い例ですお役に立てれば。以下のリンクからのコードを含めます:

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度回転します)。

于 2013-02-27T18:31:46.453 に答える