C# MSChart. How do I find the XY position of the Series Label for a StackedColumn ChartType? - Stack Overflow

I have a StackedColumn Chart. I would like to draw text at the X position of the Series centerpoint and

I have a StackedColumn Chart. I would like to draw text at the X position of the Series centerpoint and a Y position near the top of the chart. I am having trouble figuring out where the Series XY position is.

The closest thing I have been able to achieve is shown below:

I achieved this by drawing the labels as follows:

    startX = chartRect.Left + (float)(chartDailyBuildRateDisplay.ChartAreas[0].AxisX.ValueToPixelPosition(0));
    startY = chartRect.Top + 5;
    g.DrawRectangle(whitePen, startX, startY + 15, 120, 40);
    g.FillRectangle(steelBlueBrush, startX, startY + 15, 120, 40);
    g.DrawString(" Goal: " + LVDTGoal.ToString(), font, whiteBrush, startX, startY + 20);

    startX = chartRect.Left + (float)(chartDailyBuildRateDisplay.ChartAreas[0].AxisX.ValueToPixelPosition(1));
    g.DrawRectangle(whitePen, startX, startY + 15, 120, 40);
    g.FillRectangle(steelBlueBrush, startX, startY + 15, 120, 40);
    g.DrawString(" Goal: " + RVDTGoal.ToString(), font, whiteBrush, startX, startY + 20);

etc.

Obviously I need to include something else like the Axis size or something like that? Any help would be appreciated.

I have a StackedColumn Chart. I would like to draw text at the X position of the Series centerpoint and a Y position near the top of the chart. I am having trouble figuring out where the Series XY position is.

The closest thing I have been able to achieve is shown below:

I achieved this by drawing the labels as follows:

    startX = chartRect.Left + (float)(chartDailyBuildRateDisplay.ChartAreas[0].AxisX.ValueToPixelPosition(0));
    startY = chartRect.Top + 5;
    g.DrawRectangle(whitePen, startX, startY + 15, 120, 40);
    g.FillRectangle(steelBlueBrush, startX, startY + 15, 120, 40);
    g.DrawString(" Goal: " + LVDTGoal.ToString(), font, whiteBrush, startX, startY + 20);

    startX = chartRect.Left + (float)(chartDailyBuildRateDisplay.ChartAreas[0].AxisX.ValueToPixelPosition(1));
    g.DrawRectangle(whitePen, startX, startY + 15, 120, 40);
    g.FillRectangle(steelBlueBrush, startX, startY + 15, 120, 40);
    g.DrawString(" Goal: " + RVDTGoal.ToString(), font, whiteBrush, startX, startY + 20);

etc.

Obviously I need to include something else like the Axis size or something like that? Any help would be appreciated.

Share Improve this question asked Nov 20, 2024 at 17:59 TimTim 274 bronze badges 1
  • I don't quite understand where you want the text. Would you please draw a simple mspaint image to illustrate? Maybe with some more columns to so it's clear what you want it to look like with higher values. – JorisJ1 Commented Nov 24, 2024 at 13:48
Add a comment  | 

1 Answer 1

Reset to default 0

Ah, I see the problem. I started with ValueToPixelPosition(0) which I thought was the first Bar. It is not. I assume that is the xAxis itself. Changing my code to start at 1 for the first bar, solved the problem.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745548255a4632442.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信