简体   繁体   English

C#MSChart-图表区域限制

[英]C# MSChart - charts area limits

I have one Chart and three ChartArea that are aligned in view, zoom, cursor: this is my related previous post . 我有一个Chart和三个ChartArea在视图,缩放和光标上对齐: 这是我以前的相关文章 All things works well except that the three ChartArea are not aligned at the beginning. 除了三个ChartArea在开始时未对齐之外,其他所有方法都运行良好。 Following an image of the problem: 以下是问题的图片:

图示例

I think it depends from the digit's number of Y values axis. 我认为这取决于Y值轴的位数。 From some research I try the following configuration: 通过一些研究,我尝试以下配置:

// selezione e zoom
dlChart.ChartAreas[VOLTAGE_AREA].CursorX.Interval = 1;
dlChart.ChartAreas[VOLTAGE_AREA].CursorX.IsUserEnabled = true;
dlChart.ChartAreas[VOLTAGE_AREA].CursorX.IsUserSelectionEnabled = true;
// generale
dlChart.ChartAreas[VOLTAGE_AREA].AxisX.LabelStyle.Format = "dd/MM/yy - HH:mm:ss.fff";       
dlChart.ChartAreas[VOLTAGE_AREA].AxisX.ScaleView.Zoomable = true;
dlChart.ChartAreas[VOLTAGE_AREA].AxisY.LabelStyle.Format = "D5";

In witch the last row: 在女巫的最后一行:

dlChart.ChartAreas[VOLTAGE_AREA].AxisY.LabelStyle.Format = "D5";

should specifies always five digits. 应始终指定五位数。 This mitigate in some way the problem but it doesn't desappers. 这以某种方式缓解了问题,但并没有取消问题。 Furthermore with this row the program starts to throws very lots exceptions of form below any time I scroll the graph: 此外,在我滚动图表时,随着这一行,程序开始在下面引发很多形式异常:

Generate exception: 'System.FormatException' in mscorlib.dll

Does anyone knows the solution for this problem? 有谁知道这个问题的解决方案? Thanks in advance. 提前致谢。

Have you tried using the chart area alignment options? 您是否尝试过使用图表区域对齐选项? I would try something like: 我会尝试类似的东西:

//define inner plot position of the chart areas
dlChart.ChartAreas[0].InnerPlotPosition.Auto = true;
dlChart.ChartAreas[1].InnerPlotPosition.Auto = true;
dlChart.ChartAreas[2].InnerPlotPosition.Auto = true;

//set our second chart area's alignments to match our first chart area
dlChart.ChartAreas[1].AlignmentOrientation = AreaAlignmentOrientations.Vertical;
dlChart.ChartAreas[1].AlignmentStyle = AreaAlignmentStyles.All;
dlChart.ChartAreas[1].AlignWithChartArea = dlChart.ChartAreas[0].Name;

//set our third chart area's alignments to match our first chart area
dlChart.ChartAreas[2].AlignmentOrientation = AreaAlignmentOrientations.Vertical;
dlChart.ChartAreas[2].AlignmentStyle = AreaAlignmentStyles.All;
dlChart.ChartAreas[2].AlignWithChartArea = dlChart.ChartAreas[0].Name;

You may want to take control of the size of the InnerPlotPosition . 您可能希望控制InnerPlotPosition的大小。

(But Baddack's solution is simpler and more flexible!) (但是Baddack的解决方案更简单,更灵活!)

Here is an example: 这是一个例子:

After setting up a Chart with three CharAreas , setting Minima and Maxima as well as adding one DataPoint to each we get this : 在设置了具有三个 CharAreasChart ,设置MinimaMaxima以及向每个中添加一个DataPoint ,我们得到以下结果:

在此处输入图片说明

Your issue is showing clearly. 您的问题显示清楚。

After setting the InnerPlotPosition to a fixed percentage it looks like this: InnerPlotPosition设置为固定百分比后,它看起来像这样:

在此处输入图片说明

Here is how to set the InnerPlotPosition size: 这是设置InnerPlotPosition大小的方法:

ca1.InnerPlotPosition = new ElementPosition(10, 5, 80, 90);
ca2.InnerPlotPosition = new ElementPosition(10, 5, 80, 90);
ca3.InnerPlotPosition = new ElementPosition(10, 5, 80, 90);

Note that both ChartArea.Position and ChartArea.InnerPlotPosition are called 'Position' but really are areas of percentages referring to the respective containers ! 注意ChartArea.PositionChartArea.InnerPlotPosition都被称为“位置”,但实际上是指各个容器 的百分比区域

So my example has a Left distance of 10%, a Top space of 5% and Width of 80% and Height of 90%. 因此,我的示例的Left距为10%, Top间距为5%, Width为80%, Height为90%。 Which leaves 10% space at the Bottom and 5% at the Right . Bottom留出10%的空间, Right留出5%的空间。 Note : All are referring to the ChartAreas not the ClientArea of the Chart ! 注意 :所有引用的都是ChartAreas而不是ChartClientArea (Which are still at Auto , which maximizes the size.) (仍处于“ Auto ,这会最大化尺寸。)

This was my initial setup: 这是我的初始设置:

ChartArea ca1 = chart.ChartAreas[0];
ChartArea ca2 = chart.ChartAreas[1];
ChartArea ca3 = chart.ChartAreas[2];


Series s1 = chart.Series[0];
Series s2 = chart.Series.Add("Series2");
Series s3 = chart.Series.Add("Series3");

s2.ChartArea = ca2.Name;
s3.ChartArea = ca3.Name;

s1.Points.AddXY(1, 7);
s2.Points.AddXY(1, 777);
s3.Points.AddXY(1, Math.PI);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM