protected override void OnLoad(EventArgs e) { base.OnLoad(e); // new data source DataSource ds = new DataSource("PlainGraph Sample"); // new record DataRecord dr = new DataRecord("DVD"); dr.Color = Color.SkyBlue; dr.LineWeight = 2f; // line weight dr.AddData("2010", 3000); dr.AddData("2011", 3500); dr.AddData("2012", 5000); // add record ds.AddData(dr); // simple way to create record and add ds.AddData("Book", new Dictionary<string, double>(){ { "2010", 2100 }, { "2011", 2700 }, { "2012", 2550 }, }).LineWeight = 3f; graph.DataSource = ds; // update data source graph.GraphType = PlainGraphType.Column; // change chart type }
public static Color GetUnusedColor(DataSource dataSource) { Color color = new List<Color>(validColors).FirstOrDefault(c => dataSource.Records.FirstOrDefault(r => r.Color == c) == null); if (color.IsEmpty) color = Color.Black; return color; }
public void UpdateDataSource(DataSource dataSource) { this.dataSource = dataSource; recordInfo = new DataInfo(); // preprocess if (dataSource != null && dataSource.Records != null && dataSource.Records.Count != 0) { DataRecord maxSetRecord = null; bool autoFindSetKeys = DataSource.XDataKeys == null || DataSource.XDataKeys.Count == 0; recordInfo.maxEntityCount = dataSource.Records.Max(r => r.Set == null ? 0 : r.Set.Count()); recordInfo.columnTotal = new double[recordInfo.maxEntityCount]; recordInfo.columnMax = new double[recordInfo.maxEntityCount]; recordInfo.columnMin = new double[recordInfo.maxEntityCount]; recordInfo.recordCount = dataSource.Records.Count; recordInfo.recordTotal = new double[recordInfo.recordCount]; recordInfo.recordMax = new double[recordInfo.recordCount]; recordInfo.recordMin = new double[recordInfo.recordCount]; if (DataSource.Records != null) { for (int r = 0; r < DataSource.Records.Count; r++) { DataRecord row = DataSource.Records[r]; if (autoFindSetKeys && (maxSetRecord == null || row.Set.Count > maxSetRecord.Set.Count)) maxSetRecord = row; double recordTotal = 0; for (int i = 0; i < row.Set.Count; i++) { DataEntity entity = row.Set[i]; if ((this is PieGraph)) { if (entity.Style == null) entity.Style = new DataEntityStyle(); if (entity.Style.Color.IsEmpty && (this is PieGraph)) { entity.Style.Color = PlainGraphToolkit.GetRandomColor(); } } recordTotal += entity.Value; recordInfo.columnTotal[i] += entity.Value; recordInfo.columnTotalMax = Math.Max(recordInfo.columnTotalMax, recordInfo.columnTotal[i]); recordInfo.columnMax[i] = Math.Max(recordInfo.columnMax[i], entity.Value); recordInfo.columnMin[i] = Math.Min(recordInfo.columnMin[i], entity.Value); recordInfo.maxValue = Math.Max(recordInfo.maxValue, entity.Value); recordInfo.minValue = Math.Min(recordInfo.minValue, entity.Value); } recordInfo.recordTotal[r] = recordTotal; recordInfo.recordMax[r] = Math.Max(recordInfo.recordMax[r], recordTotal); recordInfo.recordMin[r] = Math.Min(recordInfo.recordMin[r], recordTotal); recordInfo.total += recordTotal; } } if (autoFindSetKeys && maxSetRecord != null) XDataKeys = (from r in maxSetRecord.Set select r.Key.ToString()).ToList(); else XDataKeys = DataSource.XDataKeys; } else { recordInfo.recordTotal = new double[0]; recordInfo.recordCount = 0; } //UpdateBounds(bounds); OnUpdateDataSource(); legends.Clear(); SelectLegends(); }