How to modify C# Chart control chartArea percentages

后端 未结 2 1600
旧时难觅i
旧时难觅i 2021-02-15 21:23

If I have a chart control with 2 chartAreas in it, the chart control by default puts the chartAreas on top of each other makes each area take 50% of the available s

2条回答
  •  悲哀的现实
    2021-02-15 21:40

    You could also set the second chart .Y position to the bottom of the first chart. That way you only need to worry about where the first chart is located. The code looks something like this:

    chart1.ChartAreas[0].Position.Y = 10;
    chart1.ChartAreas[0].Position.Height = 60;
    chart1.ChartAreas[1].Position.Y = chart1.ChartAreas[0].Position.Bottom;
    chart1.ChartAreas[1].Position.Height = 20;
    

    You can also pad the .Y position, of course, depending on how much white space you want between the charts. I used this approach for an application I built that uses multiple charts and it guarantees each chart will be properly located regardless of what is done with an individual chart.

提交回复
热议问题