标签:style blog http io ar color os 使用 sp
一个chartControl 里包括以个diagram(图表)
diagram里可以设置 x-axis与y-axis ,另外还可以设置SecondaryXAxis与SecondaryYAxis,在Series属性里可以选择使用Secondary Axis
一个diagram里包括多少个Series,一个Series表示一组(x,y)取值集合
一个diagram里可以添加多个Panel, 二Series可以设置呈现在那个panel里
Series的主要属性是DataSource,指定 ArgumentDataMember(X-Axis),ValuesDataMembers(Y-Axis)
1.自定义标注显示内,首相要设置series.LablesVisibility=True
chartControl1.CustomDrawSeriesPoint += (s, e) => { if (e.Series == chartControl1.Series["Real"]) { var it = e.SeriesPoint; var obj = it.Tag as QualifiedInfo; //Tag里是当前点的记录 e.LabelText = string.Format("{0}|{2}|{1}", obj.Disqualification, obj.Amount,obj.DisqualificationWithoutOtherDuty); } };
参考代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Windows.Forms; using DevExpress.XtraEditors; using WinDetectionClockAdmin.Model; using DevExpress.XtraCharts; using System.Threading; using DetectionClock.EFModel; namespace WinDetectionClockAdmin { public partial class frmPercentOfPassCharting : DevExpress.XtraEditors.XtraForm { private ChartControl CurCharControl { get; set; } public SynchronizationContext SyncContext { get; set; } public frmPercentOfPassCharting() { InitializeComponent(); SyncContext = SynchronizationContext.Current; #region Tab layoutControlGroup3.Shown += (s, e) => { CurCharControl = chartControl1; }; layoutControlGroup4.Shown += (s, e) => { CurCharControl = chartControl2; }; layoutControlGroup5.Shown += (s, e) => { CurCharControl = chartControl3; }; layoutControlGroup6.Shown += (s, e) => { CurCharControl = chartControl4; }; #endregion #region 自自定义Lbl显示 chartControl1.CustomDrawSeriesPoint += (s, e) => { if (e.Series == chartControl1.Series["Real"]) { var it = e.SeriesPoint; var obj = it.Tag as QualifiedInfo; e.LabelText = string.Format("{0}|{2}|{1}", obj.Disqualification, obj.Amount,obj.DisqualificationWithoutOtherDuty); } }; #endregion #region bDate.EditValue = DateTime.Now.Date.AddDays(1 - DateTime.Now.Day); eDate.EditValue = DateTime.Now.Date.Add(new TimeSpan(23, 59, 59)); ThreadPool.QueueUserWorkItem(o => { using (var ctx = DBCtx.GetCtx()) { var sql = DRecAnalyze.LoadSql("sql04.txt"); var mInfoList = ctx.ExecuteStoreQuery<MInfo>(sql).ToList(); var batnos = ctx.FO_Task.GroupBy(ent => ent.Batno).Select(ent => ent.Key).Where(ent => ent != null).ToList(); var empList = ctx.FO_TaskEmps.ToList(); SyncContext.Post(s => { team.Properties.DataSource = empList; mno.Properties.DataSource = mInfoList; batno.Properties.Items.AddRange(batnos.ToArray()); }, null); } }, null); #endregion } private void btnLoad_Click(object sender, EventArgs e) { try { var sql = DRecAnalyze.LoadSql("sql05.txt"); if (bDate.EditValue == null) throw new Exception("请指定开始时间"); if (eDate.EditValue == null) throw new Exception("请指定结束时间"); var bTime=(DateTime)bDate.EditValue; var eTime=(DateTime)eDate.EditValue; var dCondition = string.Format(" And d.AddTime>=‘{0}‘ And d.AddTime<=‘{1}‘ ", bTime.Date.ToString("yyyy-MM-dd 00:00:00"), eTime.Date.ToString("yyyy-MM-dd 23:59:59") ); var tCondition = ""; if (mno.EditValue != null ) { if (!string.IsNullOrWhiteSpace(mno.ToString())) { tCondition += string.Format(" And t.MNo=‘{0}‘", mno.EditValue.ToString()); } } if (!string.IsNullOrWhiteSpace(batno.Text)) { tCondition += string.Format(" And t.BatNo=‘{0}‘", batno.Text); } if (team.EditValue != null) { if(!string.IsNullOrWhiteSpace(team.EditValue.ToString())) { dCondition += String.Format(" And d.TaskEmpsId={0}", team.EditValue); } } var exeSql= sql.Replace("$DCondition", dCondition).Replace("$TCondition", tCondition); #region AsyncAction Action act = () => { var data = DRecAnalyze.LoadData(exeSql); var list = DRecAnalyze.AnalyzePercentOfPass(data); //所有不良项 var symptomList = DRecAnalyze.AnalyzeSymptom(data); //生产部不良项 var assembleSymptomList = DRecAnalyze.AnalyzeAssembleSymptom(data); //主要不良项 var mainSymptom = DRecAnalyze.AnalyzeMainSymptom(data); SyncContext.Post(o => { var diagram = chartControl1.Diagram as XYDiagram; if (list.Count > 0) { diagram.AxisY.Range.MaxValue = Math.Floor(list.Max(ent => ent.Disqualification) * 1.6); } chartControl1.Series["Aim"].DataSource = list; chartControl1.Series["Real"].DataSource = list; chartControl1.Series["Disqualification"].DataSource = list; chartControl2.Series["Symptom"].DataSource = symptomList; chartControl3.Series["Symptom"].DataSource = assembleSymptomList; chartControl4.Series[0].DataSource = mainSymptom; chartControl4.Series[1].DataSource = mainSymptom; chartControl4.Series[2].DataSource = mainSymptom; }, null); }; #endregion this.AsyncInvoke(act); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Filter = "Excel文件|*.xls"; fileDialog.FileName = this.Text + DateTime.Now.ToString("yyMMddHHmm"); if (fileDialog.ShowDialog() == DialogResult.OK) { CurCharControl.ExportToXls(fileDialog.FileName); XtraMessageBox.Show("操作成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } }
标签:style blog http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/wdfrog/p/4123113.html