Exemple #1
0
 public XChart(string name)
 {
     if (!ChartShemaContainer.Instance().Contains(name))
     {
         this.schema    = new ChartSchema();
         this.schema.Id = name;
     }
     else
     {
         this.schema = ChartShemaContainer.Instance().GetItem(name);
     }
 }
Exemple #2
0
        }//Method

        private void ShowReverseSeries(DataSource table, System.Web.UI.DataVisualization.Charting.ChartArea area)
        {
            //   area.AxisX.LabelStyle.Enabled = false;
            area.AxisX.LabelStyle.Interval = 0;
            area.AxisX.IntervalAutoMode    = IntervalAutoMode.FixedCount;

            string[]    xValues = null;
            ChartSchema schema  = xChart.Schema;

            if (table != null && !String.IsNullOrEmpty(schema.XField))
            {
                xValues = table.GetFieldData(schema.XField);
            }
            if (xValues == null)
            {
                return;
            }
            if (schema.SeriesList.Count < 1)
            {
                return;
            }
            SeriesSchema se0 = schema.SeriesList[0];

            area.AxisY.IsStartedFromZero = se0.IsFromY0;

            Dictionary <string, string[]> YDatas = new Dictionary <string, string[]>();

            foreach (SeriesSchema se in schema.SeriesList)
            {
                string[] values = new string[0];
                try
                {
                    values = table.GetFieldData(se.Id);
                }
                catch { }
                YDatas.Add(se.Id, values);
            }


            for (int i = 0; i < xValues.Length; i++)
            {
                string name = xValues[i];
                if (area.AxisX.IntervalType != DateTimeIntervalType.Auto &&
                    area.AxisX.IntervalType != DateTimeIntervalType.NotSet &&
                    area.AxisX.IntervalType != DateTimeIntervalType.Number)
                {
                    try { name = DateTime.Parse(name).ToString(area.AxisX.LabelStyle.Format); }
                    catch { }
                }
                if (string.IsNullOrEmpty(name) || name.Equals("null"))
                {
                    name = xValues[i];
                }
                Series series = msChart.Series.Add(name);
                series.Legend = "Default";

                series.ChartType   = (SeriesChartType)se0.ChartType;
                series.Color       = ToColor(se0.Color);
                series.MarkerStyle = (System.Web.UI.DataVisualization.Charting.MarkerStyle)se0.MarkerStyle;
                //  series.AxisLabel=
                //series.ChartArea = se.Area;
                series.BorderWidth = se0.LineWidth;
                series.Points.Clear();
                foreach (string k in YDatas.Keys)
                {
                    double v = 0;
                    string x = table.FieldCaptions[k];
                    if (x == null || x == "")
                    {
                        x = k;
                    }

                    try { v = double.Parse(YDatas[k][i]); }
                    catch { }

                    int j = series.Points.AddY(v);
                    series.Points[j].AxisLabel = x;
                }
            }
        }//Method
Exemple #3
0
        private void SetChartData(XChart xChart)
        {
            ChartSchema schema = xChart.Schema;

            DataSource table = null;

            if (!String.IsNullOrEmpty(schema.DataSource))
            {
                table = new DataSource(schema.DataSource);
                //    table.RefreshData();
                //    table.PageSize = 100;
            }

            //    Dictionary<string, ListData<string>> keyValues = table.FieldValues;
            //    Dictionary<string, string> captions = table.FieldCaptions;

            //    msChart.ChartAreas.Clear();
            //   msChart.ChartAreas[0].
            //  msChart.ChartAreas[0].Area3DStyle=ChartArea3DStyle.
            msChart.Series.Clear();

            Legend lg = msChart.Legends.FindByName("Default");

            if (lg == null)
            {
                lg = new Legend("Default");
                msChart.Legends.Add(lg);
            }

            try
            {
                lg.Docking = (Docking)int.Parse(schema.LegenPos);
            }
            catch { }

            try
            {
                lg.Alignment = (StringAlignment)int.Parse(schema.LegenAlign);
            }
            catch { }

            lg.LegendStyle = LegendStyle.Column;
            if (schema.LegenH)
            {
                lg.LegendStyle = LegendStyle.Row;
            }



            //lg.Alignment = StringAlignment.Near;
            //lg.Position.X = 0;
            //lg.Position.Y = 0;


            if (msChart.Titles.Count < 1)
            {
                msChart.Titles.Add("Chart");
            }
            Title title = msChart.Titles[0];

            title.Text = schema.Title;
            try
            {
                title.Alignment = (ContentAlignment)int.Parse(schema.TitlePos);
            }
            catch
            {
                title.Alignment = ContentAlignment.TopCenter;
            }

            //            if (schema.Width > 200)
            msChart.Width = schema.Width;
            //   if (schema.Width > 710)
            //       msChart.Width = 710;

            if (schema.Height > 100)
            {
                msChart.Height = schema.Height;
            }


            //            System.Web.UI.DataVisualization.Charting.ChartArea area = msChart.ChartAreas[0];
            msChart.ChartAreas.Clear();
            System.Web.UI.DataVisualization.Charting.ChartArea area = msChart.ChartAreas.Add("Default");

            if (!string.IsNullOrEmpty(schema.BackColor))
            {
                msChart.BackColor = ToColor(schema.BackColor);
            }

            if (!string.IsNullOrEmpty(xChart.AreaBackColor))
            {
                area.BackColor = ToColor(xChart.AreaBackColor);
            }


            area.Area3DStyle.Enable3D = schema.Is3D;
            //  area.AxisY.IsLogarithmic = true;
            //  area.AxisX.IsLogarithmic = true;

            //            area.AxisX.Interval = 0;
            area.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
            area.AxisX.IsMarginVisible  = false;
            // area.AxisX.

            area.AxisX.Interval = schema.XInterval;

            try
            {
                area.AxisX.IntervalType = (DateTimeIntervalType)int.Parse(schema.XIntervalUnit);
            }
            catch
            {
                area.AxisX.IntervalType = DateTimeIntervalType.Auto;
            }

            area.AxisX.IsLabelAutoFit    = true;
            area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont | LabelAutoFitStyles.IncreaseFont |
                                           LabelAutoFitStyles.LabelsAngleStep90 | LabelAutoFitStyles.LabelsAngleStep45 |
                                           LabelAutoFitStyles.LabelsAngleStep30;

            area.AxisX.LabelStyle.Enabled = true;
            area.AxisX.LabelStyle.Format  = schema.XLableFormat;

            //  lg.



            //            area.AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;

            //            area.AxisX.IntervalOffsetType =DateTimeIntervalType.Minutes;

            if (schema.AreaList[0].MinY == float.NaN || schema.AreaList[0].MaxY == float.NaN || schema.AreaList[0].MaxY == 0 || schema.AreaList[0].MinY == 0)
            {
                area.AxisY.Minimum = Double.NaN;
                area.AxisY.Maximum = Double.NaN;
            }
            else
            {
                // area.AxisY.IsLogarithmic = true;
                area.AxisY.Minimum = schema.AreaList[0].MinY;
                area.AxisY.Maximum = schema.AreaList[0].MaxY;
            }


            string[] xValues = null;
            if (table != null && !String.IsNullOrEmpty(schema.XField))
            {
                xValues = table.GetFieldData(schema.XField);
            }


            area.AxisX.MajorGrid.Enabled   = schema.ShowGridHLine;
            area.AxisX.MajorGrid.LineColor = ToColor(schema.GridHLineColor);
            area.AxisX.MajorGrid.LineWidth = schema.GridHLineWidth;

            area.AxisY.MajorGrid.Enabled   = schema.ShowGridVLine;
            area.AxisY.MajorGrid.LineColor = ToColor(schema.GridVLineColor);
            area.AxisY.MajorGrid.LineWidth = schema.GridVLineWidth;

            int mutYOffset = MutiYOffSetUnit;

            if (xChart.XYReverse)
            {
                ShowReverseSeries(table, area);
            }
            else
            {
                foreach (SeriesSchema se in schema.SeriesList)
                {
                    Series series = msChart.Series.Add(se.Id);
                    series.ChartType   = (SeriesChartType)se.ChartType;
                    series.Color       = ToColor(se.Color);
                    series.MarkerStyle = (System.Web.UI.DataVisualization.Charting.MarkerStyle)se.MarkerStyle;
                    //  series.AxisLabel=
                    series.ChartArea             = area.Name;
                    series.BorderWidth           = se.LineWidth;
                    series.Legend                = "Default";
                    series.YAxisType             = AxisType.Primary;
                    area.AxisY.IsStartedFromZero = se.IsFromY0;
                    // series.
                    if (se.UsingY2)
                    {
                        series.YAxisType                 = AxisType.Secondary;
                        area.AxisY2.LineColor            = series.Color;
                        area.AxisY2.LabelStyle.ForeColor = series.Color;
                        area.AxisY2.IsStartedFromZero    = se.IsFromY0;
                    }
                    if (table != null)
                    {
                        try
                        {
                            series.LegendText = table.FieldCaptions[se.Id];
                        }
                        catch
                        {
                            series.LegendText = se.Id;
                        }


                        string[] values     = new string[0];
                        string[] valuesUp   = new string[0];
                        string[] valuesDown = new string[0];

                        int count = 0;
                        try { values = table.GetFieldData(se.Id); }
                        catch { }
                        if (values != null)
                        {
                            count = values.Length;
                        }

                        try { valuesUp = table.GetFieldData(se.UpSeries); }
                        catch { }
                        if (valuesUp != null && valuesUp.Length > count)
                        {
                            count = valuesUp.Length;
                        }

                        try { valuesDown = table.GetFieldData(se.DownSeries); }
                        catch { }
                        if (valuesDown != null && valuesDown.Length > count)
                        {
                            count = valuesDown.Length;
                        }



                        for (int i = 0; i < count; i++)
                        {
                            double v = 0;
                            try
                            {
                                v = double.Parse(values[i]);
                            }
                            catch { }

                            double vUp = 0;
                            try
                            {
                                vUp = double.Parse(valuesUp[i]);
                            }
                            catch { }

                            double vDown = 0;
                            try
                            {
                                vDown = double.Parse(valuesDown[i]);
                            }
                            catch { }

                            object x = i;
                            try { x = xValues[i]; }
                            catch { }

                            if (area.AxisX.IntervalType != DateTimeIntervalType.Auto &&
                                area.AxisX.IntervalType != DateTimeIntervalType.NotSet &&
                                area.AxisX.IntervalType != DateTimeIntervalType.Number)
                            {
                                try { x = DateTime.Parse(xValues[i]); }
                                catch { }
                            }
                            else
                            {
                                try { x = Double.Parse(xValues[i]); }
                                catch { }
                            }



                            switch (series.ChartType)
                            {
                            case SeriesChartType.SplineRange:
                            case SeriesChartType.Range:
                            case SeriesChartType.RangeColumn:
                            case SeriesChartType.RangeBar:
                                //  series.Points.AddY(vUp, vDown);
                                series.Points.AddXY(x, vUp, vDown);
                                break;

                            default:
                                series.Points.AddXY(x, v);
                                break;
                            }

                            //     if (xValues != null)
                            //         series.Points[i].AxisLabel = xValues[i];
                        }

                        //       Legend lg = new Legend(se.Id);
                        // lg.s
                        //       msChart.Legends.Add(lg);
                        //     lg.Title = table.FieldCaptions[se.Id];
                        //msChart.Legends[se.Id].Title = table.FieldCaptions[se.Id];
                    }
                    if (se.CreateAxisY && !se.UsingY2)
                    {
                        this.CreateYAxis(msChart, area, series, mutYOffset, MutiYOffSetUnit);
                        mutYOffset += MutiYOffSetUnit;
                    }

                    series.PostBackValue = "#AXISLABEL";
                    series.ToolTip       = "#LEGENDTEXT \n" +
                                           "X轴:#VALX\n" +
                                           "Y轴:#VAL";
                }
            }
            //msChart.Style=

            //    foreach (BI.Schema.ChartArea areaSch in schema.AreaList)
            //    {
            //        System.Web.UI.DataVisualization.Charting.ChartArea chartArea = msChart.ChartAreas.Add(areaSch.Id);
            //    }
        }//Method