コード例 #1
0
        public string GetChart()
        {
            chart = new BubbleChartData(defaultAttributes);
            var xMax = float.MinValue;
            var xMin = float.MaxValue;
            var yMax = float.MinValue;
            var yMin = float.MaxValue;

            for (int i = 0; i < Input.Rows.Count; i++)
            {
                if (Input.Rows[i].Values[3] != null || Input.Rows[i].Values[5] != null)
                {
                    xMax = GetMax(Input.Rows[i].Values[3] != "--" ? Input.Rows[i].Values[3]:"0", xMax);
                    xMin = GetMin(Input.Rows[i].Values[3] != "--" ? Input.Rows[i].Values[3] : "0", xMin);
                    yMax = GetMax(Input.Rows[i].Values[4] != "--" ? Input.Rows[i].Values[4] : "0", yMax);
                    yMin = GetMin(Input.Rows[i].Values[4] != "--" ? Input.Rows[i].Values[4] : "0", yMin);
                }
            }

            chart.Attributes.Add("xaxisminvalue", (xMin - 15).ToString());
            chart.Attributes.Add("xaxismaxvalue", (xMax + 15).ToString());
            chart.Attributes.Add("yaxisminvalue", (yMin - 50).ToString());
            chart.Attributes.Add("yaxismaxvalue", (yMax + 50).ToString());

            if (PeriodType.ToUpper() == "YTD" || PeriodType.ToUpper() == "MAT")
            {
                string[] headers = Input.Columns[3].Name.Split('_').ToArray();
                chart.Attributes.Add("xaxisname", PeriodType + " " + headers[0]);
                headers = Input.Columns[4].Name.Split('_').ToArray();
                chart.Attributes.Add("yaxisname", PeriodType + " " + headers[0]);
            }
            else
            {
                var monthDict = new Dictionary <string, int>()
                {
                    { "Jan", 1 },
                    { "Feb", 2 },
                    { "Mar", 3 },
                    { "Apr", 4 },
                    { "May", 5 },
                    { "Jun", 6 },
                    { "Jul", 7 },
                    { "Aug", 8 },
                    { "Sep", 9 },
                    { "Oct", 10 },
                    { "Nov", 11 },
                    { "Dec", 12 }
                };

                var qtrDict = new Dictionary <string, int>()
                {
                    { "QTR1", 1 },
                    { "QTR2", 2 },
                    { "QTR3", 3 },
                    { "QTR4", 4 }
                };

                if (PeriodType == "MTH")
                {
                    int year;
                    int.TryParse(EndDate.Split(' ')[1], out year);
                    int prevYear = year - 1;
                    chart.Attributes.Add("xaxisname", "Long-Term (" + EndDate + "-" + EndDate.Split(' ')[0] + " " + prevYear + ")");

                    int monthIndex = monthDict[EndDate.Split(' ')[0]];
                    if (monthIndex > 3)
                    {
                        monthIndex = monthIndex - 3;
                    }
                    else
                    {
                        monthIndex = 12 + (monthIndex - 3);
                    }
                    string oldMonth = monthDict.FirstOrDefault(x => x.Value == monthIndex).Key;
                    chart.Attributes.Add("yaxisname", "Short-Term (" + EndDate + "-" + oldMonth + " " + EndDate.Split(' ')[1] + ")");
                }
                if (PeriodType == "QTR")
                {
                    int year;
                    int.TryParse(EndDate.Split(' ')[2], out year);
                    int prevYear = year - 1;
                    chart.Attributes.Add("xaxisname", "Long-Term (" + EndDate + "-" + EndDate.Split(' ')[0] + " " + EndDate.Split(' ')[1] + " " + prevYear + ")");

                    //int monthIndex = monthDict[EndDate.Split(' ')[1]];
                    int monthIndex = qtrDict[EndDate.Split(' ')[0] + EndDate.Split(' ')[1]];
                    if (monthIndex > 3)
                    {
                        monthIndex = monthIndex - 3;
                    }
                    else
                    {
                        monthIndex = 12 + (monthIndex - 3);
                    }
                    string oldMonth = monthDict.FirstOrDefault(x => x.Value == monthIndex).Key;
                    chart.Attributes.Add("yaxisname", "Short-Term (" + EndDate + "-" + oldMonth + " " + EndDate.Split(' ')[1] + ")");
                }
            }

            var diffBetXInterval = Convert.ToInt16(Math.Floor((xMax - xMin) / 5));

            for (var i = 0; i < xMax; i += diffBetXInterval)
            {
                var category = new Category();
                category.Attributes.Add("label", i.ToString());
                chart.Categories.Category.Add(category);
            }

            var dataset = new DataSet();

            foreach (var row in Input.Rows)
            {
                String.Format("{0:0.00}", row.Values[3] != "--" ? row.Values[3] : "0");
                String.Format("{0:0.00}", row.Values[4] != "--" ? row.Values[4] : "0");
                String.Format("{0:0.00}", row.Values[5] != "--" ? row.Values[5] : "0");
                string toolText = "Series-" + row.Values[1] + ", Sales: " + row.Values[5];

                Set set = new Set()
                {
                    Attributes = new Dictionary <string, string>()
                    {
                        { "x", row.Values[3] },
                        { "y", row.Values[4] },
                        { "z", row.Values[5] },
                        { "name", row.Values[1] },
                        { "color", _colorList.GetNextColor() },
                        { "toolText", toolText }
                    }
                };

                dataset.Add(set);
            }
            chart.Dataset.Add(dataset);

            return(chart.RenderWithScript("98%", "360"));
        }