您的位置:首页 > 其它

如何让TeeChart.Net自定义轴正常显示在图表区域

2013-08-22 16:52 519 查看
TeeChart.Net是一款功能全面、性能稳定的图表控件,受深受用户好评。在使用TeeChart.Net的过程中还是会遇到各种难题。今天为大家解决TeeChart.Net添加自定义轴的问题,如果遇到自定义轴的标签和标题都超出图表区域,比如出现在图表标题上面。应该如何解决呢?



大多数情况下,我们并不知道问题出在什么地方。如遇到这种情况,就只有一步一步操作,找出问题,最后再解决问题。

操作环境:

系统:Windows 7(64位)

控件版本:TeeChart.Net v2013.4

一、设置一个不同的顶边

结果:只能在图表标题上方添加一定空间,坐标轴标签依旧在图表上方,问题没有解决。

二、修改代码,在顶部添加水平自定义轴,增加顶部边缘,重新定位图表标题

代码:

Axis customAxis;

private void InitializeChart()

{

tChart1.Aspect.View3D = false;

colorGrid1 = new ColorGrid(tChart1.Chart);

colorGrid1.FillSampleValues();

customAxis = new Axis(tChart1.Chart);

tChart1.Axes.Custom.Add(customAxis);

customAxis.Horizontal = true;

colorGrid1.HorizAxis = HorizontalAxis.Both;

colorGrid1.CustomHorizAxis = customAxis;

tChart1.Draw();

customAxis.OtherSide = true;

tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;

tChart1.Panel.MarginTop = 50;

tChart1.Header.CustomPosition = true;

tChart1.Header.Left = tChart1.Width / 2;

tChart1.Header.Top = 0;

button1.Click +=button1_Click;

}

结果:经过这样操作后,单个轴标签在图表区域显示。

三、继续添加下面代码

colorGrid1.HorizAxis = HorizontalAxis.Both;

colorGrid1.CustomHorizAxis = customAxis;

结果:图表制作顺利进行,但是按钮上的标签消失。

四、精简代码

只添加:colorGrid1.HorizAxis = HorizontalAxis.Both;

呼出customAxis.labels.Clear()工具,再添加另外的标签,新标签中仍然有许多轴标签在顶部。

五、不在使用自定义轴,而使用默认按钮坐标轴和图表顶轴

添加以下代码:

private void InitializeChart()

{

tChart1.Aspect.View3D = false;

colorGrid1 = new ColorGrid(tChart1.Chart);

colorGrid1.FillSampleValues();

colorGrid1.HorizAxis = HorizontalAxis.Both;

AddCustomLabels(tChart1.Axes.Top);

tChart1.Draw();

tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;

tChart1.Panel.MarginTop = 50;

tChart1.Header.CustomPosition = true;

tChart1.Header.Left = tChart1.Width / 2;

tChart1.Header.Top = 0;

button1.Click += button1_Click;

}

private void AddCustomLabels(Axis a)

{

a.Labels.Items.Clear();

a.Labels.Items.Add(colorGrid1.XValues[5], "Point 1");

}



六、使用辅助,分配自定义轴

用下面的代码完成操作:

Axis customAxis;

Steema.TeeChart.Styles.ColorGrid colorGrid1;

Steema.TeeChart.Styles.ColorGrid auxiliarygrid;

private void InitializeChart()

{

tChart1.Aspect.View3D = false;

colorGrid1 = new ColorGrid(tChart1.Chart);

auxiliarygrid = new ColorGrid(tChart1.Chart);

colorGrid1.FillSampleValues();

customAxis = new Axis(tChart1.Chart);

tChart1.Axes.Custom.Add(customAxis);

customAxis.Horizontal = true;

colorGrid1.HorizAxis = HorizontalAxis.Bottom;

auxiliarygrid.CustomHorizAxis = customAxis;

auxiliarygrid.ShowInLegend = false;

AddCustomLabels(customAxis);

tChart1.Draw();

customAxis.OtherSide = true;

tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;

tChart1.Panel.MarginTop = 50;

tChart1.Header.CustomPosition = true;

tChart1.Header.Left = tChart1.Width / 2;

tChart1.Header.Top = 0;

}

总结:在第四个步骤,可以看出该图表是一个系列下多自定义轴图表,所以在系列中需要分配每一个轴,由于,前面三个步骤没有如此做,导致轴标签无法全部正常显示在图表区域;第五、第六两个步骤中,移除顶轴标签,再增加了另外的标签,并对多轴进行了分配,所以轴标签显示正常。

原文地址:http://www.evget.com/zh-CN/Info/catalog/19422.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息