admin管理员组

文章数量:1023782

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.

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.

本文标签: C MSChart How do I find the XY position of the Series Label for a StackedColumn ChartTypeStack Overflow