如何水平绘制四个(或更多)工作区? [英] how to draw four (or more) workareas horizontally?

查看:20
本文介绍了如何水平绘制四个(或更多)工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是绘制 1/2/3/4(取决于备注)图表的和平代码:

Here is a peace of code which draws 1/2/3/4 (depends on remarks) charts:

private void button1_Click(object sender, EventArgs e)
    {
        List<int> queue = new List<int>();
        queue.Add(1); queue.Add(2); queue.Add(3); queue.Add(4);
        chart1.ChartAreas.Add(queue[0].ToString());
        chart1.ChartAreas.Add(queue[1].ToString());
        chart1.ChartAreas.Add(queue[2].ToString());
        chart1.ChartAreas.Add(queue[3].ToString());
        chart1.Series.Add("test1");
        chart1.Series.Add("test2");
        chart1.Series.Add("test3");
        chart1.Series.Add("test4");
        chart1.Series["test1"].ChartArea = "1";
        chart1.Series["test2"].ChartArea = "2";
        chart1.Series["test3"].ChartArea = "3";
        chart1.Series["test4"].ChartArea = "4";
        Random rdn = new Random();
        for (int i = 0; i < 50; i++)
        {
            chart1.Series["test1"].Points.AddXY(rdn.Next(0, 10), rdn.Next(0, 10));
            chart1.Series["test2"].Points.AddXY(rdn.Next(0, 10), rdn.Next(0, 10));
            chart1.Series["test3"].Points.AddXY(rdn.Next(0, 10), rdn.Next(0, 10));
            chart1.Series["test4"].Points.AddXY(rdn.Next(0, 10), rdn.Next(0, 10));
        }
        chart1.Series["test1"].ChartType = SeriesChartType.FastLine;
        chart1.Series["test2"].ChartType = SeriesChartType.FastLine;
        chart1.Series["test3"].ChartType = SeriesChartType.FastLine;
        chart1.Series["test4"].ChartType = SeriesChartType.FastLine;
    }

如果我绘制两个或三个图表,它会水平显示如下:

If I draw two or three charts it appears horizontally something like:

…………

…………

…………

…………

…………

当我添加第四个图表区域时,它开始创建第二个列"

When I add fourth chartarea it starts create second "column"

……………………

……………………

如何强制使用一列进行布局?我找到了Position"属性,但找不到正确使用它的方法:(

What to do to force layout with one column ? I have found "Position" property but couldn't find the way how to use it correctly :(

推荐答案

我认为所有的对齐属性实际上更多的是关于数据对齐而不是区域本身..

I think all the alignment properties actually are more about data aligning than about the areas themselves..

看起来默认的 Position = Auto 会以它自己的关于如何最好地利用空间的想法获胜,直到你关闭它;所以我相信你必须在代码中设置 ChartAreasPositions.这是一个可以玩的例子:

Looks like the default Position = Auto will win with its own ideas about how to use the space best, until you switch it off; so I believe that you have to set the Positions of the ChartAreas in code. Here is an example to play with:

float dist = 1f;
float h = 23f;
float w = 80f;

CA1.Position = new ElementPosition(dist, dist * 2 + h * 0, w, h);
CA2.Position = new ElementPosition(dist, dist * 3 + h * 1, w, h);
CA3.Position = new ElementPosition(dist, dist * 4 + h * 2, w, h);
CA4.Position = new ElementPosition(dist, dist * 5 + h * 3, w, h);

ElementPosition 是保持图表总面积百分比 (!) 的浮点数.我允许有一点距离并将 ChartAreas 设置为 23% 的高度和 80% 的宽度.

The four numbers of an ElementPosition are floats that hold percentages (!) of the total chart area. I have allowed a little distance and set the ChartAreas to 23% height and 80% width.

好消息是这些数字在调整大小期间会保持不变..

The good news is that these numbers will hold during resize..

这是一个截图(没有数据):

Here is a screenshot (without data):

这些东西这么难找是不是很奇怪?(这是我第三次尝试..)

Isn't is strange that these things are so very hard to find out? (This is my 3rd try at it..)

这篇关于如何水平绘制四个(或更多)工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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