1、CustomDrawAxisLabel : 接管此事件来获得轴标签。定制轴标签
private void chartControl1_CustomDrawAxisLabel(object sender, CustomDrawAxisLabelEventArgs e) { AxisBase axis = e.Item.Axis; if (axis is AxisY || axis is AxisY3D || axis is RadarAxisY) { double axisValue = (double)e.Item.AxisValue; if (axisValue < 0) { e.Item.TextColor = Color.Red; } else if (axisValue > 0) { e.Item.Text = "+" + e.Item.Text; e.Item.TextColor = Color.Green; } else if (axisValue == 0) { e.Item.Text = "Zero"; } } }
2、ObjectHotTracked:鼠标指针悬停位置
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) { if (e.AdditionalObject is AxisTitle) { MessageBox.Show(e.AdditionalObject.GetType().ToString()); } }
3、CustomDrawSeries :自定义绘制系列
private void chartControl1_CustomDrawSeries(object sender, CustomDrawSeriesEventArgs e) { // Find all Bar Series by their view type,and fill them with Aqua color. if (e.Series.View is BarSeriesView) e.SeriesDrawOptions.Color = Color.Aqua; // Find the series by its name, and change its line style to dash-dot-dot. (Here it's assumed that the series view type is LineSeriesView). if (e.Series.Name == "Line Series") ((LineDrawOptions)e.SeriesDrawOptions).LineStyle.DashStyle = DevExpress.XtraCharts.DashStyle.DashDotDot; // Find all Point Series by the type of its DrawOptions, and change their marker kind to diamond. if (e.SeriesDrawOptions.GetType() == typeof(PointDrawOptions)) ((PointDrawOptions)e.SeriesDrawOptions).Marker.Kind = MarkerKind.Diamond; }
4、CustomDrawSeriesPoint:自定义绘制系列点
private void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) { // These changes will be applied to Bar Series only. BarDrawOptions drawOptions = e.SeriesDrawOptions as BarDrawOptions; if (drawOptions == null) return; // Get the fill options for the series point. drawOptions.FillStyle.FillMode = DevExpress.XtraCharts.FillMode.Gradient; RectangleGradientFillOptions options =drawOptions.FillStyle.Options as RectangleGradientFillOptions; if (options == null) return; // Get the value at the current series point. double val = e.SeriesPoint[0]; // If the value is less than 1, hide the point's label. if (e.SeriesPoint[0] < 1) { e.LabelText = ""; } // If the value is less than 2.5, then fill the bar with green colors. if (val < 2.5) { options.Color2 = Color.FromArgb(154, 196, 84); drawOptions.Color = Color.FromArgb(81, 137, 3); drawOptions.Border.Color = Color.FromArgb(100, 39, 91, 1); } // ... if the value is less than 5.5, then fill the bar with yellow colors. else if (val < 5.5) { options.Color2 = Color.FromArgb(254, 233, 124); drawOptions.Color = Color.FromArgb(249, 170, 15); drawOptions.Border.Color = Color.FromArgb(60, 165, 73, 5); } // ... if the value is greater, then fill the bar with red colors. else { options.Color2 = Color.FromArgb(242, 143, 112); drawOptions.Color = Color.FromArgb(199, 57, 12); drawOptions.Border.Color = Color.FromArgb(100, 155, 26, 0); } }