devexpress图表Chart开发日志
Legend设置
控制
chartControl1.Legend.Direction = LegendDirection.LeftToRight;
chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside;
chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
说明:
Direction
LegendDirection.TopToBottomLegendDirection.BottomToTop
LegendDirection.LeftToRight
LegendDirection.RightToLeft
AlignmentVertical
LegendAlignmentVertical.TopOutside
LegendAlignmentVertical.Top
LegendAlignmentVertical.Center
LegendAlignmentVertical.Bottom
LegendAlignmentVertical.BottomOutside
AlignmentHorizontal
LegendAlignmentHorizontal.LeftOutside
LegendAlignmentHorizontal.Left
LegendAlignmentHorizontal.Center
LegendAlignmentHorizontal.Right
LegendAlignmentHorizontal.RightOutside
标题 Title
C# 全选
DevExpress.XtraCharts.ChartTitle chartTitle1 = new DevExpress.XtraCharts.ChartTitle(); chartTitle1.Font = new System.Drawing.Font("Tahoma", 18F, System.Drawing.FontStyle.Bold);
chartTitle1.Text = "2021年统计图";
chartTitle1.Visibility = DevExpress.Utils.DefaultBoolean.True;
this.chartControl1.Titles.AddRange(new DevExpress.XtraCharts.ChartTitle[] {chartTitle1});
隐藏 Legend
C# 全选
this.chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
显示Series值 Label
C# 全选
series1.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
Series值 Label 控制属性
C# 全选
// 显示Label
series2.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
// 对齐方式,左对齐,右对齐,居中对齐
series2.Label.TextAlignment = StringAlignment.Center;
// 文本方向,横向,竖向
series2.Label.TextOrientation = TextOrientation.Horizontal;
// Label位置,条形图
(series2.Label as BarSeriesLabel).Position = BarSeriesLabelPosition.Top;
示例:
效果图:
代码:
chartControl1.Legend.Direction = LegendDirection.LeftToRight;
chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside;
chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
完整代码:
/// <summary> /// 显示图表 /// </summary> private void DoRefreshChart(string category, List<TreeTableModel> data) { chartControl1.Series.Clear(); List<Series> SeriesList = new List<Series>(); Series seriesMy = new Series(category, ViewType.Spline);//曲线 Series seriesAvg = new Series("同行同层平均" + category, ViewType.Spline);//曲线 Series seriesGood = new Series("同行同层优秀" + category, ViewType.Spline);//曲线 foreach (var p in data) { seriesMy.Points.Add(new SeriesPoint(p.Label, p.Value)); seriesAvg.Points.Add(new SeriesPoint(p.Label, p.ValueAvg)); seriesGood.Points.Add(new SeriesPoint(p.Label, p.ValueGood)); } SetCommonOption(seriesMy); SetCommonOption(seriesAvg); SetCommonOption(seriesGood); SeriesList.Add(seriesMy); SeriesList.Add(seriesAvg); SeriesList.Add(seriesGood); chartControl1.Series.AddRange(SeriesList.ToArray()); XYDiagram diagram = (XYDiagram)chartControl1.Diagram; diagram.AxisX.Title.Visibility = DevExpress.Utils.DefaultBoolean.False; diagram.AxisX.Title.Alignment = StringAlignment.Center; diagram.AxisX.Title.Text = "日期"; diagram.AxisX.Title.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True; diagram.AxisX.Title.Font = new Font("Tahoma", 12, FontStyle.Bold); diagram.AxisX.NumericScaleOptions.GridSpacing = 60; diagram.AxisX.Label.Visible = true; diagram.AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.False; ; diagram.AxisY.Title.Alignment = StringAlignment.Center; diagram.AxisY.Title.Text = "数值"; diagram.AxisY.Title.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True; ; diagram.AxisY.Title.Font = new Font("Tahoma", 12, FontStyle.Bold); chartControl1.Legend.Direction = LegendDirection.LeftToRight; chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside; chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Left; }
GarsonZhang www.yesdotnet.com
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post YES开发框架