大家好,又见面了,我是你们的朋友全栈君。
本文转载自:http://www.cnblogs.com/forgetu/archive/2010/06/07/Visifire-AxisLabels.html
这篇中简单介绍一下 Axis (坐标轴)的主要的几个属性的设置。

Visifire废话少说,主要的几个属性及属性的设置和意思请看下面的示例代码和注释:
Chart chart = new Chart |
{ |
Width = 500, |
Height = 300, |
View3D = true, |
Bevel = true |
}; |
chart.Titles.Add(new Title |
{ |
Text = "坐标轴设置示例" |
}); |
|
Axis xaxis = new Axis(); |
// 设置坐标轴的背景色 |
xaxis.Background = new SolidColorBrush(Colors.Gray); |
// 设置坐标轴上两点间的距离,这个属性不能和ScrollBarScale属性同时设置 |
xaxis.ClosestPlotDistance = 2; |
// 启用或禁用坐标轴 |
xaxis.Enabled = true; |
// 坐标轴的最小值是否从0开始 |
xaxis.StartFromZero = true; |
// 坐标轴上两点间所表示的值的间隔 |
xaxis.Interval = 2; |
// 坐标轴上两点间所表示的值的间隔的类型,数字或时间 |
xaxis.IntervalType = IntervalTypes.Number; |
// 坐标轴线的样式 |
xaxis.LineStyle = LineStyles.Dashed; |
// 附加到坐标轴文本上的前缀 |
xaxis.Prefix = "$"; |
// 附加到坐标轴文本上的后缀 |
xaxis.Suffix = "*"; |
|
chart.AxesX.Add(xaxis); |
|
Axis yaxis = new Axis(); |
// 是否启用 |
yaxis.Enabled = true; |
// 前缀 |
yaxis.Prefix = "$"; |
// 后缀 |
yaxis.Suffix = "*"; |
// 坐标轴文本的格式化字符串,可以是任何有效的数字或时间格式化字符串 |
yaxis.ValueFormatString = "#0,0#"; |
// 坐标轴类型,可以是primary或secondary,这个属性只能用于Y轴,只有在设置了DataSeries的AxisYType属性后才会启用 |
yaxis.AxisType = AxisTypes.Secondary; |
|
chart.AxesY.Add(yaxis); |
|
DataSeries series = new DataSeries(); |
// 设置坐标轴的类型为 secondary |
series.AxisYType = AxisTypes.Secondary; |
|
series.RenderAs = RenderAs.Column; |
|
series.DataPoints.Add(new DataPoint |
{ |
YValue = random.Next(1000, 50000), |
XValue = 3 |
}); |
series.DataPoints.Add(new DataPoint |
{ |
YValue = random.Next(1000, 50000), |
XValue = 4 |
}); |
series.DataPoints.Add(new DataPoint |
{ |
YValue = random.Next(1000, 50000), |
XValue = 6 |
}); |
series.DataPoints.Add(new DataPoint |
{ |
YValue = random.Next(1000, 50000), |
XValue = 7 |
}); |
|
chart.Series.Add(series); |
下面是使用 Xaml 设置的代码
<vc:Chart Grid.Column="0" View3D="True" Bevel="True" Width="500" Height="300"> |
<vc:Chart.Titles> |
<vc:Title Text="坐标轴设置示例" /> |
</vc:Chart.Titles> |
<vc:Chart.AxesX> |
<vc:Axis Enabled="True" StartFromZero="True" Interval="1" IntervalType="Number" LineStyle="Dashed" Prefix="$" Suffix="*" /> |
</vc:Chart.AxesX> |
<vc:Chart.AxesY> |
<vc:Axis Enabled="True" Prefix="$" Suffix="*" ValueFormatString="#0,0#" /> |
</vc:Chart.AxesY> |
<vc:Chart.Series> |
<vc:DataSeries> |
<vc:DataSeries.DataPoints> |
<vc:DataPoint YValue="43000" /> |
<vc:DataPoint YValue="32000" /> |
<vc:DataPoint YValue="28000" /> |
<vc:DataPoint YValue="40000" /> |
</vc:DataSeries.DataPoints> |
</vc:DataSeries> |
</vc:Chart.Series> |
</vc:Chart> |
转载于:https://www.cnblogs.com/sivanwong/archive/2010/10/25/1860390.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162795.html原文链接:https://javaforall.net
