tchart
我用的是C# 从网上看到资料拷贝过来备忘,共同学习下:
- 设置chart标题:axTChart1.Header.Text.Add("标题");
- 修改标题:axTChart1.Header.Text.set_Item(index, "修改后的标题");
- 表头标题清除: axTChart1.Header.Text.Clear();
- 移除第n(int)个标题:axTChart1.Header.Text.Remove(1);
- 标题居中:axTChart1.Header.Alignment = TeeChart.ETitleAlignment.taCenter;
- 标题向右移动50:axTChart1.Header.CustomPosition = true;
axTChart1.Header.Left= axTChart1.Header.Left + 50;
- 标题背景:axTChart1.Header.Transparent = false;//背景不透明
axTChart1.Header.Brush.Style = TeeChart.EBrushStyle.bsBackCrossSmall;//背景样式
- 标题背景阴影颜色:axTChart1.Header.Transparent = false;
axTChart1.Header.ShadowColor=(uint)(1255);
说明(Legend):
- 说明是否可见:axTChart1.Legend.Visible = true;
- 说明框内分割线是否可见:axTChart1.Legend.DividingLines.Visible = true;
- 说明框分割线颜色:axTChart1.Legend.Color=(uint)(2201);
- 说明框向下移位(量50):TChart1.Legend.TopPos =50
- 说明框内图示的长度:axTChart1.Legend.ColorWidth = 150;
- 说明框内文字颜色:axTChart1.Legend.Font.Color = (uint)(130000);
- 说明框阴影部分的颜色和深度:axTChart1.Legend.ShadowColor=(uint)(13000);
axTChart1.Legend.ShadowSize = 6;
面板(Panel):
- 载入面板背景图片:axTChart1.Panel.BackImageLoad(@"e:\121.jpg");
- 面板斜度设置:
1
2
3
4
|
axTChart1.Panel.Gradient.Visible = true ; axTChart1.Panel.Gradient.StartColor = ( uint )(1); axTChart1.Panel.Gradient.EndColor = ( uint )(13000); axTChart1.Panel.Gradient.Direction = TeeChart.EGradientDirection.gdFromTopLeft; |
3D效果:
- 隐藏3D效果:axTChart1.Aspect.View3D = false;
Chart分页:
- 运行时显示ChartEditor对话框:axTChart1.ShowEditor();
- 每一页最多可以显示的点的数量:axTChart1.Page.MaxPointsPerPage = 20;
- 下一页&&上一页(这时需要设置一个按钮来完成): axTChart1.Page.Next();
axTChart1.Page.Previous();
- 跳到最后一页:axTChart1.Page.Current = axTChart1.Page.Count;
- 决定最后一页放缩:axTChart1.Page.ScaleLastPage = false;
- 获取当前页码:MessageBox.Show(axTChart1.Page.Current.ToString());
坐标(Axis):
- 添加20个点到序列上:
1234567
for
(
int
i = 1; i <= 20; i++)
{
axTChart1.Series(1).Add(i*i, i.ToString(), (
uint
)(50000));
}
- 设置轴刻度(Y轴为Axis.Left ,X轴为Axis.Bottom)
- 设置Y轴的终点和起点,最小刻度值:
1
2
3
4
|
axTChart1.Axis.Left.Automatic = false ; //必须有,或者用.AutomaticMaximum等代替 axTChart1.Axis.Left.Maximum = 600; //最大值的声明必须在最小值先,否则报错 axTChart1.Axis.Left.Minimum = 500; axTChart1.Axis.Left.Increment = 20; |
- 将Y轴最小值固定,最大值自动增长:出现严重错误
- 将Y轴最大值固定,最小值自动时应:
1
2
3
|
axTChart1.Axis.Left.AutomaticMaximum = false ; axTChart1.Axis.Left.Maximum = 600; axTChart1.Axis.Left.AutomaticMinimum = true ; |
(* 结论: 在设置最大最小值时,没设置最大值就设置最小值将失败)
自定义轴标签(添加轴事件):
1
2
3
|
private void axTChart1_OnGetAxisLabel( object sender, AxTeeChart.ITChartEvents_OnGetAxisLabelEvent e) { e.labelText = "p" + e.valueIndex.ToString(); } |
设置轴自定义标签:
1
2
3
4
|
axTChart1.Axis.Left.Logarithmic = true ; axTChart1.Axis.Left.Increment = 0; //默认为0 axTChart1.Axis.Left.SetMinMax(0, 10000); axTChart1.Axis.Left.Labels.ValueFormat = "#e+0" ; |
自定义交叉坐标轴:只能在chart Editor中设置。
坐标轴点击事件:
1
2
3
4
5
|
private void axTChart1_OnClickAxis( object sender, AxTeeChart.ITChartEvents_OnClickAxisEvent e) { MessageBox.Show(axTChart1.Axis.Bottom.CalcPosPoint(e.x).ToString()); //显示位置 } |
Series:
- 删除第5个点(从0开始):axTChart1.Series(0).Delete(5);
- 添加一个坐标:axTChart1.Series(0).AddNull("label");
- 添加一个Series:
1
2
3
4
|
TeeChart.ESeriesClass ns = new TeeChart.ESeriesClass(); int index = axTChart1.AddSeries(ns); axTChart1.Series(index).HorizontalAxis = TeeChart.EHorizontalAxis.aTopAxis; axTChart1.Series(index).VerticalAxis = TeeChart.EVerticalAxis.aRightAxis; |
- 设置series1的数据源为series0:
1
2
|
axTChart1.Series(1).DataSource = "Series0" ; axTChart1.Series(1).SetFunction(TeeChart.EFunctionType.tfCopy); |
- 交换两个Series的顺序:
1
|
axTChart1.ExchangeSeries(0, 1); //After exchanging Series, the index for the Series will be changed. |
- 显示第三个位置的Y值:MessageBox.Show(axTChart1.Series(0).YValues.get_Value(3).ToString());
- 修改第9个位置的Y值为21:axTChart1.Series(0).YValues.set_Value(int.Parse(9,21);
- 将第有个位置的坐标向X轴正向移动5个坐标:axTChart1.Series(0).XValues.set_Value(5,9);
- 清除绘图:axTChart1.Series(0).Clear();
- 清除刻度:axTChart1.Axis.Visible = false;
- 清除底部刻度:axTChart1.Axis.Bottom.Visible = false;
- Margin和左边相距 20% :axTChart1.Panel.MarginLeft = 20;