public ChartDataMultipleSeries(List<SeriesDataPoints> datapoints_col, SeriesLabels labels)
        {
            if (datapoints_col == null)
            {
                throw new System.ArgumentNullException("datapoints_col");
            }

            if (labels == null)
            {
                throw new System.ArgumentNullException("labels");
            }

            foreach (var series in datapoints_col)
            {
                int num_rows = series.Length;
                if (num_rows != labels.Length)
                {
                    string msg =
                        string.Format("Number of values and labels do not match. {0} values given and {1} labels given",
                                      series.Length, labels.Length);

                    throw new System.ArgumentException(msg);
                }
            }

            this.DataPointsCollection = datapoints_col;
            this.XAxisLabels = labels;
        }
Exemple #2
0
        public ChartDataSingleSeries(SeriesDataPoints values, SeriesLabels labels)
        {
            if (values == null)
            {
                throw new System.ArgumentNullException("values");
            }

            if (labels == null)
            {
                throw new System.ArgumentNullException("labels");
            }

            if (values.Length != labels.Length)
            {
                string msg =
                    string.Format("Number of values and labels do not match. {0} values given and {1} labels given",
                                  values.Length, labels.Length);

                throw new System.ArgumentException(msg);
            }
            this.Values      = values;
            this.XAxisLabels = labels;
        }
        public ChartDataSingleSeries(SeriesDataPoints values, SeriesLabels labels)
        {
            if (values == null)
            {
                throw new System.ArgumentNullException("values");
            }

            if (labels == null)
            {
                throw new System.ArgumentNullException("labels");
            }

            if (values.Length != labels.Length)
            {
                string msg =
                    string.Format("Number of values and labels do not match. {0} values given and {1} labels given",
                                  values.Length, labels.Length);

                throw new System.ArgumentException(msg);
            }
            this.Values = values;
            this.XAxisLabels = labels;
        }
    /// <summary>
    /// Creates the chart.
    /// </summary>
    /// <param name="currency">The currency.</param>
    /// <param name="labels">The labels.</param>
    /// <param name="values">The values.</param>
    private void CreateChart(Currency currency, string[] labels, decimal[] values)
    {
        // Label style (x and y label)
        LabelStyle labelStyleX = new LabelStyle();

        labelStyleX.Font      = new Font("Arial", 10);
        labelStyleX.ForeColor = Color.Black;
        labelStyleX.Name      = "xStyle";
        c_chartVisits.LabelStyles.Add(labelStyleX);

        // Data point style
        DataPointLabelStyle dataPointStyle = c_chartVisits.DataPointLabelStyles.CreateNew("CustomStyle");

        if (dataPointStyle != null)
        {
            dataPointStyle.ForeColor     = System.Drawing.Color.Black;
            dataPointStyle.Font          = new System.Drawing.Font("Arial", 10, System.Drawing.GraphicsUnit.Point);
            dataPointStyle.LabelPosition = LabelPositionKind.AboveVertical;
        }

        // Chart settings
        c_chartVisits.View.Kind                = ProjectionKind.TwoDimensional;
        c_chartVisits.View.LightsOffOn2D       = false;
        c_chartVisits.ResizeMarginsToFitLabels = true;
        //c_chartVisits.MainStyle = "Line";

        if (ViewState["ChartWidth"] != null)
        {
            c_chartVisits.Width = new Unit((double)ViewState["ChartWidth"]);
        }
        else
        {
            ViewState["ChartWidth"] = c_chartVisits.Width.Value;
        }


        // If more than 24 columns,
        if (labels.Length > 24)
        {
            c_chartVisits.Width = labels.Length * 23;
            //title.Font = new System.Drawing.Font("Arial", 10, System.Drawing.GraphicsUnit.Point);
            dataPointStyle.Font = new System.Drawing.Font("Arial", 10, System.Drawing.GraphicsUnit.Point);
        }

        // Line style
        LineStyle2D lineStyle2D = new LineStyle2D();

        lineStyle2D.Color      = ColorTranslator.FromHtml("#0266fb");
        lineStyle2D.Width      = 2;
        lineStyle2D.ShadeWidth = 2;
        c_chartVisits.LineStyles2D.Add(lineStyle2D);

        // Series style
        SeriesStyle seriesStyle = new SeriesStyle();

        seriesStyle.ChartKind       = ChartKind.Rectangle;
        seriesStyle.LineStyle2DName = lineStyle2D.Name;
        c_chartVisits.SeriesStyles.Add(seriesStyle);

        // Series
        Series s1 = new Series("S1");

        s1.StyleName = seriesStyle.Name;
        s1.Parameters["pointAreaAttributes"] = "alt=\"#[Param(y)]\"";
        s1.DataPointParameters["color"]      = System.Drawing.Color.Black;

        c_chartVisits.RenderAreaMap = true;
        c_chartVisits.Series.Add(s1);
        c_chartVisits.DefineValue("S1:y", values);
        c_chartVisits.DefineValue("x", labels);
        c_chartVisits.DataBind();

        SeriesLabels sLabels = s1.CreateAnnotation("y", "CustomStyle");

        for (int i = 0; i < sLabels.Count; i++)
        {
            DataPointLabel label = sLabels[i];
            decimal        value = Convert.ToDecimal(label.Text);
            label.Text = value.ToString(currency.GetNumberFormatInfo(CultureInfo.CurrentUICulture));
        }

        // Y axis
        AxisAnnotation yAnnotation = c_chartVisits.CoordinateSystem.YAxis.AxisAnnotations["Y@Xmin"];

        //yAnnotation.AxisTitle = CurrentModule.Strings.GetValue("Visits", FoundationContext.LanguageID, true);
        yAnnotation.AxisTitleStyleName = "xStyle";
        yAnnotation.LabelStyleName     = "xStyle";
        yAnnotation.AxisTitleOffsetPts = 35;
        foreach (AxisLabel label in yAnnotation.Labels)
        {
            decimal value;
            if (decimal.TryParse(label.Text, out value))
            {
                label.Text = value.ToString(currency.GetNumberFormatInfo(CultureInfo.CurrentUICulture));
            }
        }

        // X axis
        AxisAnnotation xAnnotation = c_chartVisits.CoordinateSystem.XAxis.AxisAnnotations["X@Ymin"];

        xAnnotation.AxisTitleStyleName = "xStyle";
        xAnnotation.LabelStyleName     = "xStyle";
        xAnnotation.HOffset            = 3;
        xAnnotation.VOffset            = 0;
        xAnnotation.RotationAngle      = 45;


        // Background
        StripSet yStripSet1 = c_chartVisits.CoordinateSystem.PlaneXY.StripSets["YinPlaneXY"];

        yStripSet1.Color               = Color.White;
        yStripSet1.AlternateColor      = Color.FromArgb(242, 242, 242);
        c_chartVisits.Frame.FrameKind  = ChartFrameKind.Thin2DFrame;
        c_chartVisits.Frame.FrameColor = Color.Gray;
        c_chartVisits.BackGradientKind = GradientKind.Center;
    }