Beispiel #1
0
 private void setLegendStyle(StackColumnType type)
 {
     if (type == StackColumnType.Comparison)
     {
         this.stackcolumn.Legends[0].LegendStyle = LegendStyle.Column;
     }
     else if (type == StackColumnType.TimeSeries)
     {
         this.stackcolumn.Legends[0].LegendStyle = LegendStyle.Row;
     }
 }
Beispiel #2
0
    /// <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="barHatchStyles">The hatchstyles to use for the series. The number of styles 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, StackColumnType type, string unitCode, Color[] barColors, ChartHatchStyle[] barHatchStyles, string[] legendTexts)
    {
        if (series != barColors.Length)
        {
            throw (new ArgumentException("number of colors must correspond to the number of series"));
        }

        if (series != barHatchStyles.Length)
        {
            throw (new ArgumentException("number of hatch styles 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.stackcolumn.Series.Clear();
        this.stackcolumn.Legends[0].CustomItems.Clear();

        for (int i = 0; i < series; i++)
        {
            Series bar = this.stackcolumn.Series.Add(i.ToString());
            bar.ChartType         = SeriesChartType.StackedColumn;
            bar.Color             = barColors[i];
            bar.IsVisibleInLegend = false; //use custom legends instead.
            bar.BackHatchStyle    = barHatchStyles[i];

            if (legendTexts != null)
            {
                LegendItem item = new LegendItem();
                item.Name           = legendTexts[i];
                item.SeriesName     = legendTexts[i];
                item.BorderColor    = Color.Black;
                item.Color          = bar.Color;
                item.BackHatchStyle = bar.BackHatchStyle;
                item.ImageStyle     = LegendImageStyle.Rectangle;

                this.stackcolumn.Legends[0].CustomItems.Add(item);
            }
        }

        this.stackcolumn.Legends[0].CustomItems.Reverse();
    }
Beispiel #3
0
    private void setXaxis(IEnumerable <TimeSeriesUtils.BarData> bars)
    {
        StackColumnType type = Type;

        Axis axisX = this.stackcolumn.ChartAreas[0].AxisX;

        int startYear = bars.Min(b => b.Year);
        int endYear   = bars.Max(b => b.Year);

        double interval = 1; //default

        if (type == StackColumnType.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);
        }
    }