如何清除图表中的白色区域? [英] How to remove white areas in Chart?
问题描述
如何在图表(C#,Visual Studio 2013)中删除白色区域(1,2)和减少轴(3)的宽度。图表宽度约16000像素。
PS:如果图表短宽度(1000-2000像素)没有白色区域,轴的宽度正常。
大白空间是按比例放大的距离
您可以在放大图表
宽度时将位置设置为较小的值。
请注意,您可以定位的元素的相关属性是 ElementPosition
类型的
- ..它的值不是像素,而是相应容器的百分比。
- ..初始值都设置为
0
,表示自动
。
所以你需要计算每次调整图表的大小,你不能初始设置一个单一的属性,因为其他人仍然在 0
。
这些元素可以放置:
-
Chartarea(s)
-
InnerPlotPosition
code> -
图例
-
注释
,我们此处不需要
Major
- 和 MinorTickMarks
从 Auto
数值。下面是一个在 Chart.Width
16,000
像素工作的示例:
ChartArea ca = chart1.ChartAreas [0];
图例L = chart1.Legends [0];
ca.Position = new ElementPosition(0.2f,5,99,90);
ca.InnerPlotPosition = new ElementPosition(0.3f,1,99.5f,90);
L.Position = new ElementPosition(99.03f,5,0.75f,22);
ca.AxisY.MajorTickMark.Size = 0.15f;
ChartArea ca = chart1.ChartAreas [0];
ca.Position.X = 0.1f;
ca.InnerPlotPosition.X = 0.3f;
Axis ay = ca.AxisY;
ay.MajorTickMark.Size = 0.1f;
另外请注意,我找不到任何方法来定位 YAxis
标签;所以它通常会关闭到左边。您可以在 Paint
事件中<:code> DrawString :
private void chart1_Paint(object sender,PaintEventArgs e)
{
Axis ay = chart1.ChartAreas [0] .AxisY;
Graphics g = e.Graphics;
g.TranslateTransform(-20,180);
g.RotateTransform(270);
使用(SolidBrush brush = new SolidBrush(ay.TitleForeColor))
g.DrawString(ay.Title,ay.TitleFont,brush,22,22);
}
我在这里也使用了一些合适的值,
我不确定是否应该放大图表这样。相反,我相信您应该允许用户在缩放图表中缩放和滚动!How can I remove white areas (1,2) and reduce width of axis (3) in chart (C#, Visual Studio 2013). Width of chart about 16000px. PS: If width of chart short (1000-2000 px) there are no white areas and width of axis is normally.
The large white spaces are the proportionally enlarged distances.
You can set the positions to smaller values when you enlarge the Chart
width.
Note that relevant property of the elements you can position is of type ElementPosition
and that..
- ..its values are not in pixels but in percentages of the respective containers.
- ..the initial values are all set to
0
, which meansAutomatic
.
So you need to calculate the position each time you resize the chart and you can't initially set a single property since the others are still at 0
.
These elements can be positioned:
- The
Chartarea(s)
- The
InnerPlotPosition
of (each)Chartarea
- The
Legend(s)
- a few others, like
Annotations
, we don't need here
You can also set the sizes of the Major
- and MinorTickMarks
from Auto
to a suitable numeric value. Here is an example that work here for a Chart.Width
of 16,000
pixels:
ChartArea ca = chart1.ChartAreas[0];
Legend L = chart1.Legends[0];
ca.Position = new ElementPosition(0.2f, 5, 99, 90);
ca.InnerPlotPosition = new ElementPosition(0.3f, 1, 99.5f, 90);
L.Position = new ElementPosition(99.03f, 5, 0.75f, 22);
ca.AxisY.MajorTickMark.Size = 0.15f;
ChartArea ca = chart1.ChartAreas[0];
ca.Position.X = 0.1f;
ca.InnerPlotPosition.X = 0.3f;
Axis ay = ca.AxisY;
ay.MajorTickMark.Size = 0.1f;
Also note that I can't see any way to position the YAxis
label; so it will usually be off to the left. You can DrawString
it in the Paint
event, though:
private void chart1_Paint(object sender, PaintEventArgs e)
{
Axis ay = chart1.ChartAreas[0].AxisY;
Graphics g = e.Graphics;
g.TranslateTransform(-20, 180);
g.RotateTransform(270);
using (SolidBrush brush = new SolidBrush(ay.TitleForeColor))
g.DrawString(ay.Title, ay.TitleFont, brush, 22, 22);
}
I use some suitable values here as well but you will want to work out new ones for other sizes!
But: I'm not sure whether you should enlarge the chart this way. Instead I believe you should allow the user to zoom in and scroll in the zoomed chart!
这篇关于如何清除图表中的白色区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!