public static PlotModel CreatePlotModel( string chartName, IDictionary <string, IEnumerable <DataErrorPoint> > data, ChartType chartType) { var plotModel = new PlotModel { Title = chartName, Background = OxyColor.FromRgb(255, 255, 255), TitleFont = FONT_NAME, TitleFontSize = FONT_SIZE + 6, TitleFontWeight = FontWeights.Bold, IsLegendVisible = chartType != ChartType.Pie && data.Count > 1, LegendPosition = LegendPosition.TopLeft, LegendBorderThickness = 1, LegendBorder = OxyColor.FromRgb(0, 0, 0), LegendBackground = OxyColor.FromRgb(255, 255, 255), LegendFontSize = FONT_SIZE, LegendFont = FONT_NAME, LegendFontWeight = FontWeights.Normal, DefaultColors = CreatePalette(data).Colors }; //gets max X and Y axis values GetAxesMinMax(data.Values, out var maxX, out var minY, out var maxY); // Y-axis plotModel.Axes.Add(new LinearAxis { Minimum = minY, Maximum = maxY, MajorGridlineStyle = LineStyle.Dot, Font = FONT_NAME, FontSize = FONT_SIZE + 1 //FontWeight = FontWeights.Bold }); // X-axis var xAxis = chartType.Equals(ChartType.Column) ? new CategoryAxis() : new LinearAxis(); xAxis.Minimum = chartType.Equals(ChartType.Column) ? -0.5 : 0; xAxis.Maximum = maxX - (chartType.Equals(ChartType.Column) ? 0.5 : 1); xAxis.Position = AxisPosition.Bottom; xAxis.Font = FONT_NAME; xAxis.FontSize = FONT_SIZE + 1; //xAxis.FontWeight = FontWeights.Bold; plotModel.Axes.Add(xAxis); return(plotModel); }
public ChartBuilder AddDataX(string[] labels) { if (_type.Equals(ChartType.scatter)) { return(null); } if (_hasDataset && (labels.Length != _chart.Data.Datasets[0].Data.Length)) { throw new Exception("Label array length does not match the defined dataset length."); } _chart.Data.Labels = labels; _hasLabels = true; return(this); }
public static void genChartBySql(string sql, ChartType type) { SqlDataReader reader; DbUtil.ExecuteReader(out reader, sql); if (!reader.HasRows) { reader.Close(); return; } PointPairList list = new PointPairList(); //计数器,取每个产品的12个值 int i = 0; //结束符,标志该产品图已生成 bool ok = false; string productCode = ""; string title = ""; string s = ""; getGraphControl(); while (reader.Read()) { while (ok) { if (reader.Read()) { if (!productCode.Equals(reader[1].ToString())) { ok = false; productCode = ""; break; } } else { reader.Close(); return; } } if (productCode.Equals("")) { i = 0; getGraphControl(); list = new PointPairList(); productCode = reader[1].ToString(); if (type.Equals(ChartType.Price_Index_Week)) { title = reader[3].ToString() + "[周价格指数]"; s = "piw"; } else if (type.Equals(ChartType.Price_Index_Week_Total)) { title = "周价格总指数"; s = "piw"; } else if (type.Equals(ChartType.PriceRing_Index_Week)) { title = reader[3].ToString() + "[周环比价格指数]"; s = "riw"; } else if (type.Equals(ChartType.PriceRing_Index_Week_Totle)) { title = "周环比价格总指数"; s = "riw"; } else if (type.Equals(ChartType.Price_Index_Month)) { title = reader[3].ToString() + "[月价格指数]"; s = "pim"; } else if (type.Equals(ChartType.Price_Index_Month_Total)) { title = "月价格总指数"; s = "pim"; } else if (type.Equals(ChartType.PriceRing_Index_Month)) { title = reader[3].ToString() + "[月环比价格指数]"; s = "rim"; } else if (type.Equals(ChartType.PriceRing_Index_Month_Total)) { title = "月环比价格总指数"; s = "rim"; } else if (type.Equals(ChartType.Fash_Index_Month)) { title = reader[3].ToString() + "[月流行指数]"; s = "fim"; } else if (type.Equals(ChartType.Fash_Index_Month_Total)) { title = "月流行总指数"; s = "fim"; } else if (type.Equals(ChartType.Scale_Index_Month)) { title = reader[3].ToString() + "[月规模指数]"; s = "sim"; } else if (type.Equals(ChartType.Scale_Index_Month_Total)) { title = "月规模总指数"; s = "sim"; } else if (type.Equals(ChartType.Confidence_Index_Month)) { title = reader[3].ToString() + "[月信心指数]"; s = "cim"; } else if (type.Equals(ChartType.Confidence_Index_Month_Total)) { title = "月信心总指数"; s = "cim"; } else if (type.Equals(ChartType.Boom_Index_Month)) { title = reader[3].ToString() + "[月景气指数]"; s = "bim"; } else if (type.Equals(ChartType.Boom_Index_Month_Total)) { title = "月景气总指数"; s = "bim"; } } if (!productCode.Equals(reader[1].ToString())) { //生成本产品图片 genChart(ct, productCode, s, title, list); ok = false; //下一个产品 i = 0; getGraphControl(); list = new PointPairList(); productCode = reader[1].ToString(); if (type.Equals(ChartType.Price_Index_Week)) { title = reader[3].ToString() + "[周价格指数]"; s = "piw"; } else if (type.Equals(ChartType.Price_Index_Week_Total)) { title = "周价格总指数"; s = "piw"; } else if (type.Equals(ChartType.PriceRing_Index_Week)) { title = reader[3].ToString() + "[周环比价格指数]"; s = "riw"; } else if (type.Equals(ChartType.PriceRing_Index_Week_Totle)) { title = "周环比价格总指数"; s = "riw"; } else if (type.Equals(ChartType.Price_Index_Month)) { title = reader[3].ToString() + "[月价格指数]"; s = "pim"; } else if (type.Equals(ChartType.Price_Index_Month_Total)) { title = "月价格总指数"; s = "pim"; } else if (type.Equals(ChartType.PriceRing_Index_Month)) { title = reader[3].ToString() + "[月环比价格指数]"; s = "rim"; } else if (type.Equals(ChartType.PriceRing_Index_Month_Total)) { title = "月环比价格总指数"; s = "rim"; } else if (type.Equals(ChartType.Fash_Index_Month)) { title = reader[3].ToString() + "[月流行指数]"; s = "fim"; } else if (type.Equals(ChartType.Fash_Index_Month_Total)) { title = "月流行总指数"; s = "fim"; } else if (type.Equals(ChartType.Scale_Index_Month)) { title = reader[3].ToString() + "[月规模指数]"; s = "sim"; } else if (type.Equals(ChartType.Scale_Index_Month_Total)) { title = "月规模总指数"; s = "sim"; } else if (type.Equals(ChartType.Confidence_Index_Month)) { title = reader[3].ToString() + "[月信心指数]"; s = "cim"; } else if (type.Equals(ChartType.Confidence_Index_Month_Total)) { title = "月信心总指数"; s = "cim"; } else if (type.Equals(ChartType.Boom_Index_Month)) { title = reader[3].ToString() + "[月景气指数]"; s = "bim"; } else if (type.Equals(ChartType.Boom_Index_Month_Total)) { title = "月景气总指数"; s = "bim"; } } i++; double x = new XDate((DateTime)reader[0]); double y = double.Parse(reader[2].ToString()); list.Add(x, y); // Create a text label from the Y data value,当X轴为DateAsOrdinal类型时,将忽略掉X轴本来的值 TextObj text = new TextObj(y.ToString("f2"), i, y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center); text.ZOrder = ZOrder.A_InFront; // Hide the border and the fill text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; text.FontSpec.Size = 20; ct.GraphPane.GraphObjList.Add(text); if (i >= 12) { //生成本产品图片 genChart(ct, productCode, s, title, list); ok = true; } } //确保最后一张图片也生成 if (productCode.Equals("00") && (i >= 12)) { reader.Close(); } else { genChart(ct, productCode, s, title, list); reader.Close(); } ct.Dispose(); ct = null; }