Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

' 创建数据系列
Dim ds = New XYDataSeries() ds.XValuesSource = x ds.ValuesSource = y
'设置事件处理器
AddHandler ds.PlotElementLoaded, AddressOf PlotElement_Loaded
' 添加数据系列至图表
C1Chart1.Data.Children.Add(ds)
' 设置图表类型
C1Chart1.ChartType = ChartType.LineSymbols ...
' event handler
Sub PlotElement_Loaded(ByVal sender As Object, ByVal args As EventArgs)
Dim pe = CType(sender, PlotElement)
If Not TypeOf pe Is Lines Then
Dim dp As DataPoint = pe.DataPoint ' 正规化 y-值(范围从 0 到 1)
Dim nval As Double = 0.5 * (dp.Value + 1)
' 填充色从蓝色(-1)变化到红色(+1)
pe.Fill = New SolidColorBrush(Color.FromRgb(CByte(255 * nval), _ 0, CByte(255 * (1 - nval))))
End If
End Sub

C#

// 创建数据数组
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="043b5e9e-7d27-454c-bcbe-33b20e7f9030"><ac:plain-text-body><![CDATA[ int npts = 100; double[] x = new double[npts], y = new double[npts]; for (int ipt = 0; ipt < npts; ipt++)
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a2063254-2f1b-4d0a-ae20-bbb4e1ddd72a"><ac:plain-text-body><![CDATA[ { x[ipt] = ipt; y[ipt] = Math.Sin(0.1 * ipt); }
]]></ac:plain-text-body></ac:structured-macro>
// 创建数据系列
XYDataSeries ds = new XYDataSeries(); ds.XValuesSource = x; ds.ValuesSource = y;
//设置事件处理器
ds.PlotElementLoaded += (s, e) => { PlotElement pe = (PlotElement)s; if (!(pe is Lines)) // skip lines
{
DataPoint dp = pe.DataPoint;

// 正规化 y-值(范围从 0 到 1)
double nval = 0.5*(dp.Value + 1);
// 填充色从蓝色(-1)变化到红色(+1)
pe.Fill = new SolidColorBrush(
Color.FromRgb((byte)(255 * nval), 0, (byte)(255 * (1-nval))));
}
};
// 添加数据系列至图表
c1Chart1.Data.Children.Add(ds);
// 设置图表类型
c1Chart1.ChartType = ChartType.LineSymbols;
提示技巧四:数据点标签及工具提示提示技巧四:数据点标签及工具提示为创建一个数据点标签或工具提示,您应当设置模版至PointLabelTemplate或者PointToolTipTemplate属性。以下示例代码将演示如何显示每一个数据点的索引。

...