private void setLegendStyle(StackColumnTypeEPER type) { if (type == StackColumnTypeEPER.Comparison) { this.stackcolumnEPER.Legends[0].LegendStyle = LegendStyle.Column; } else if (type == StackColumnTypeEPER.TimeSeries) { this.stackcolumnEPER.Legends[0].LegendStyle = LegendStyle.Row; } }
/// <summary> /// Initialize the bars. /// </summary> /// <param name="series">The number of series to include in the bar chart</param> /// <param name="type">The type of time series chart</param> /// <param name="barcolors">The colors to use for the series. The number of colors given must corresponds to the number of series</param> /// <param name="legendTexts">The texts to be shown in the legends. If null, no legends will be shown</paparam> /// <param name="unitCode">The unit code corresponding to the y-axis</param> public void Initialize(int series, StackColumnTypeEPER type, string unitCode, Color[] barColors, string[] legendTexts) { if (series != barColors.Length) { throw (new ArgumentException("number of colors must correspond to the number of series")); } if (legendTexts != null && series != legendTexts.Length) { throw (new ArgumentException("number of legend tetxs must correspond to the number of series")); } //set in view state this.Type = type; setAxisYTitle(LOVResources.UnitName(unitCode)); setFont(); setLegendStyle(type); //add series and legends this.stackcolumnEPER.Series.Clear(); this.stackcolumnEPER.Legends[0].CustomItems.Clear(); for (int i = 0; i < series; i++) { Series bar = this.stackcolumnEPER.Series.Add(i.ToString()); bar.ChartType = SeriesChartType.StackedColumn; bar.Color = barColors[i]; bar.IsVisibleInLegend = false; //use custom legends instead. if (legendTexts != null && !legendTexts[i].Equals("")) { LegendItem item = new LegendItem(); item.Name = legendTexts[i]; item.SeriesName = legendTexts[i]; item.BorderColor = Color.Black; item.Color = bar.Color; item.ImageStyle = LegendImageStyle.Rectangle; this.stackcolumnEPER.Legends[0].CustomItems.Add(item); } } this.stackcolumnEPER.Legends[0].CustomItems.Reverse(); }
private void setXaxis(IEnumerable <TimeSeriesUtils.BarData> bars) { StackColumnTypeEPER type = Type; Axis axisX = this.stackcolumnEPER.ChartAreas[0].AxisX; int startYear = bars.Min(b => b.Year); int endYear = bars.Max(b => b.Year); double interval = 1; //default if (type == StackColumnTypeEPER.Comparison) { if (startYear != endYear) { interval = endYear - startYear; } } double offset = endYear != startYear ? interval / 2 : interval - 0.001; axisX.Interval = interval; axisX.Minimum = startYear - offset; axisX.Maximum = endYear + offset; axisX.IntervalOffset = offset; foreach (var bar in bars) { int year = bar.Year; CustomLabel label = new CustomLabel(); label.FromPosition = year - offset; //avoid precision problems label.ToPosition = year + offset; //avoid precision problems label.Text = year.ToString(); axisX.CustomLabels.Add(label); } }