如何修改C#图表控件chartArea百分比 [英] How to modify C# Chart control chartArea percentages

查看:538
本文介绍了如何修改C#图表控件chartArea百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个带有2个chartAreas的图表控件,则默认情况下,该图表控件会将chartAreas放在另一个顶部,使每个区域占据图表控件可用大小的50%.

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 size of the chart control.

是否可以更改chartAreas的百分比,以便让我说,顶部的图表占据75%的面积,底部的图表占据25%的面积?

Is there a way to change the chartAreas' percent so that I could say, have the top chart take 75% of the area, and the bottom chart take 25%?

推荐答案

因此,我最终找到了它,但是我认为它没有很好的记录.每个chartArea都具有属性 ChartArea.Position .此属性的类型为 ElementPosition ,并包含4与该问题有关的属性.

So, I eventually found it, but I do not think that it is very well documented. There each chartArea has the property ChartArea.Position. This property of the type ElementPosition, and contains 4 properties that are relevant to this problem.

Height:获取或设置图表元素的高度.
宽度:获取或设置图表元素的宽度.
X:获取或设置适用图表元素左上角的相对X坐标.
Y:获取或设置适用图表元素左上角的相对Y坐标.

Height: Gets or sets the height of a chart element.
Width: Gets or sets the width of a chart element.
X: Gets or sets the relative X-coordinate of the top-left corner of an applicable chart element.
Y: Gets or sets the relative Y-coordinate of the top-left corner of an applicable chart element.

深入研究时,HeightWidth属性也以相对坐标表示,因此您只能输入0-100.

When you dig deeper, the Height and Width properties are also stated in relative coordinates, such that you can only input 0 - 100.

基本上,您必须更改每个高度,并移动每个Y来移动它们.初始创建后,它将不会自动调整其他数字.

Basically, you have to change each height, and each Y to move shift them. After the initial creation, it will not automatically adjust the other numbers.

例如,如果我只是将chartArea [1]的Height更改为较小的值,那么它仍然会锚定在以前的位置,这很有意义,在其下方留有很多空白.

For instance, if I just change the Height of chartArea[1] to something smaller, it will still be anchored where it was previously, as would make sense, leaving a lot of white space below it.

如果我然后增加chartArea [0]的Height,它可能会覆盖我们刚刚调整大小的chartArea [1].因此,我必须设置chartArea [1]的Y向下移动,以使其不会被覆盖,并且空白消失了.

If I then increase the Height of chartArea[0], it may draw over chartArea[1] that we just resized. So then I have to set the Y of chartArea[1] to move it down, so that it is not drawn over, and the white space is gone.

因此,为了获得与我在问题中所问类似的内容,我将其设置为:

So, to get something similar to what I asked in the question, I set it to:

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

为使说明更加清楚,我将把这些chartAreas所在的Chart控件称为父级".

To make this explanation a bit more clear, I will refer to the Chart control that these chartAreas are in as "the parent".

这些是百分比,但是在本示例中,我们假设父母的尺寸为100像素.

These are percentages, but for this example, let us assume that the parent's size is 100 pixels.

这会将第一个chartArea设置为以10像素开始显示,并使高度大约60像素.然后,它开始以70像素显示第二个chartArea,并使它的高度大约为20像素.

如果此图表的高度为200px,则比例将相同,但实际像素将为两倍(因此将第一个图表区域设置为60将使其高度为120px).

This sets the first chartArea start displaying at 10 px, and makes it about 60px tall. It then starts displaying the second chartArea at 70px, and makes it about 20px tall.

If this chart was 200px tall, then the proportions would be the same, but the actually pixels would be double (so setting the first chart area to 60 would make it 120px tall).

我确实在实际程序中做了一些填充,因为它具有覆盖轴标签的标题,但是我觉得这些数字有助于更好地解释它.

I did pad this a bit more in my real program, because this has titles overwriting axis labels, but I felt these numbers helped explain it better.

这篇关于如何修改C#图表控件chartArea百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆