public IHttpActionResult SingleTrendChart(ChartQuery note)
        {
            JsonObject json = new JsonObject();

            if (Convert.ToDateTime(note.BeginTime) >= Convert.ToDateTime(note.EndTime))
            {
                json["Error"] = "Begin Time <End Time";
                return(Ok(json));;
            }
            try
            {
                int AB = Convert.ToInt32(note.AB);
                if (note.Isdelegate)
                {
                    AB = 4;
                }


                ChartCreater cc = new ChartCreater();
                int          i;
                i = cc.FillData(note.SampleName, note.LOT_NO, note.Line, note.Property, Convert.ToDateTime(note.BeginTime), Convert.ToDateTime(note.EndTime), AB);
                TrendChart dic = new TrendChart();
                cc.SingleTrendChart(ref dic);

                #region red
                decimal[][] red = null;
                if (dic.Number != null && dic.testScores != null && dic.Number.Length != 0 && dic.testScores.Length != 0)
                {
                    red = new decimal[dic.Number.Length][];
                    for (int r = 0; r < dic.Number.Length; r++)
                    {
                        red[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        red[r][0] = dic.Number[r];
                        red[r][1] = dic.testScores[r];
                    }
                    json["RedPoint"] = red;
                }
                #endregion

                #region 超线的点1
                if (dic.overCLNumbers != null && dic.overCLScores != null &&
                    dic.overCLNumbers.Length != 0 && dic.overCLScores.Length != 0 && dic.overCLNumbers.Length == dic.overCLScores.Length)
                {
                    decimal[][] over1 = new decimal[dic.overCLNumbers.Length][];
                    for (int r = 0; r < dic.overCLNumbers.Length; r++)
                    {
                        over1[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        over1[r][0] = dic.overCLNumbers[r];
                        over1[r][1] = dic.overCLScores[r];
                    }
                    json["Over1"] = over1;
                }
                #endregion

                #region 超线的点2
                if (dic.overNumbers != null && dic.overTestScores != null &&
                    dic.overNumbers.Length != 0 && dic.overTestScores.Length != 0 && dic.overNumbers.Length == dic.overTestScores.Length)
                {
                    decimal[][] over2 = new decimal[dic.overNumbers.Length][];
                    for (int r = 0; r < dic.overNumbers.Length; r++)
                    {
                        over2[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        over2[r][0] = dic.overNumbers[r];
                        over2[r][1] = dic.overTestScores[r];
                    }
                    json["Over2"] = over2;
                }
                #endregion
                json["ChartData"]    = dic;
                json["ChartCreater"] = cc;
                List <decimal> maxs = new List <decimal>();
                List <decimal> mins = new List <decimal>();
                if (dic.testScores != null && dic.testScores.Length != 0)
                {
                    maxs.Add(dic.testScores.Max());
                    mins.Add(dic.testScores.Min());
                }
                if (dic.overCLScores != null && dic.overCLScores.Length != 0)
                {
                    maxs.Add(dic.overCLScores.Max());
                    mins.Add(dic.overCLScores.Min());
                }
                if (dic.overTestScores != null && dic.overTestScores.Length != 0)
                {
                    maxs.Add(dic.overTestScores.Max());
                    mins.Add(dic.overTestScores.Min());
                }
                json["Model"]    = dic;
                json["maxValue"] = GetMinValueChart(dic, maxs.Max(), mins.Min(), true);
                json["minValue"] = GetMinValueChart(dic, maxs.Max(), mins.Min(), false);
                json["maxPoint"] = maxs.Max();
                json["minPoint"] = mins.Min();

                return(Ok(json));
            }
            catch (Exception e)
            {
                json["Error"] = e.Message + "-" + e.StackTrace;
                return(Ok(json));
            }
        }
        public IHttpActionResult MRChart(ChartQuery note)
        {
            JsonObject json = new JsonObject();

            if (Convert.ToDateTime(note.BeginTime) >= Convert.ToDateTime(note.EndTime))
            {
                json["Error"] = "Begin Time <End Time";
                return(Ok(json));;
            }
            try
            {
                int AB = Convert.ToInt32(note.AB);
                if (note.Isdelegate)
                {
                    AB = 4;
                }

                ChartCreater cc = new ChartCreater();
                int          i;
                i = cc.FillData(note.SampleName, note.LOT_NO, note.Line, note.Property, Convert.ToDateTime(note.BeginTime), Convert.ToDateTime(note.EndTime), AB);
                TrendChart dic = new TrendChart();
                cc.IChart(ref dic);
                json["Model"] = dic;
                #region 趋势图

                if (dic.Number != null && dic.testScores != null && dic.Number.Length != 0 && dic.testScores.Length != 0)
                {
                    decimal[][] red = new decimal[dic.Number.Length][];
                    for (int r = 0; r < dic.Number.Length; r++)
                    {
                        red[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        red[r][0] = dic.Number[r];
                        red[r][1] = dic.testScores[r];
                    }
                    json["Trend"] = red;

                    List <decimal> allLines = new List <decimal>();
                    if (dic.USL != decimal.MinValue)
                    {
                        allLines.Add(dic.USL);
                    }
                    if (dic.LSL != decimal.MinValue)
                    {
                        allLines.Add(dic.LSL);
                    }
                    if (dic.CL != decimal.MinValue)
                    {
                        allLines.Add(dic.CL);
                    }
                    if (dic.UCL != decimal.MinValue)
                    {
                        allLines.Add(dic.UCL);
                    }
                    if (dic.LCL != decimal.MinValue)
                    {
                        allLines.Add(dic.LCL);
                    }
                    if (dic.LUCL != decimal.MinValue)
                    {
                        allLines.Add(dic.LUCL);
                    }
                    if (dic.LLCL != decimal.MinValue)
                    {
                        allLines.Add(dic.LLCL);
                    }
                    if (dic.X != decimal.MinValue)
                    {
                        allLines.Add(dic.X);
                    }

                    #region 最大值的点
                    if (red != null && red.Length != 0)
                    {
                        decimal[][] maxSpots = new decimal[2][];
                        maxSpots[0]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        maxSpots[0][0] = red[0][0];
                        maxSpots[0][1] = allLines.Max();
                        maxSpots[1]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        maxSpots[1][0] = red[red.Length - 1][0];
                        maxSpots[1][1] = allLines.Max();

                        json["MaxSpots"] = maxSpots;
                    }
                    #endregion

                    #region 最小值的点
                    if (red != null && red.Length != 0)
                    {
                        decimal[][] minSpots = new decimal[2][];
                        minSpots[0]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        minSpots[0][0] = red[0][0];
                        minSpots[0][1] = allLines.Min();
                        minSpots[1]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        minSpots[1][0] = red[red.Length - 1][0];
                        minSpots[1][1] = allLines.Min();

                        json["MinSpots"] = minSpots;
                    }
                    #endregion
                }
                #endregion

                #region 超线的点1
                if (dic.overCLNumbers != null && dic.overCLScores != null &&
                    dic.overCLNumbers.Length != 0 && dic.overCLScores.Length != 0 && dic.overCLNumbers.Length == dic.overCLScores.Length)
                {
                    decimal[][] over1 = new decimal[dic.overCLNumbers.Length][];
                    for (int r = 0; r < dic.overCLNumbers.Length; r++)
                    {
                        over1[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        over1[r][0] = dic.overCLNumbers[r];
                        over1[r][1] = dic.overCLScores[r];
                    }
                    json["Over1"] = over1;
                }
                #endregion

                #region 超线的点2
                if (dic.overNumbers != null && dic.overTestScores != null &&
                    dic.overNumbers.Length != 0 && dic.overTestScores.Length != 0 && dic.overNumbers.Length == dic.overTestScores.Length)
                {
                    decimal[][] over2 = new decimal[dic.overNumbers.Length][];
                    for (int r = 0; r < dic.overNumbers.Length; r++)
                    {
                        over2[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        over2[r][0] = dic.overNumbers[r];
                        over2[r][1] = dic.overTestScores[r];
                    }

                    json["Over2"] = over2;
                    //ViewBag.Over2 = over2;
                }
                #endregion

                #region MRChart
                TrendChart dicR = new TrendChart();
                cc.MRChart(ref dicR);

                #region 趋势图
                if (dicR.Number != null && dicR.testScores != null &&
                    dicR.Number.Length != 0 && dicR.testScores.Length != 0 && dicR.Number.Length == dicR.testScores.Length)
                {
                    decimal[][] trendR = new decimal[dicR.Number.Length][];
                    for (int r = 0; r < dicR.Number.Length; r++)
                    {
                        trendR[r]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        trendR[r][0] = dicR.Number[r];
                        trendR[r][1] = dicR.testScores[r];
                    }

                    json["TrendR"] = trendR;
                    List <decimal> allLinesMR = new List <decimal>();
                    if (dicR.UCL != decimal.MinValue)
                    {
                        allLinesMR.Add(dicR.UCL);
                    }
                    if (dicR.LCL != decimal.MinValue)
                    {
                        allLinesMR.Add(dicR.LCL);
                    }
                    if (dicR.MR != decimal.MinValue)
                    {
                        allLinesMR.Add(dicR.MR);
                    }
                    #region MR图最大值的点
                    if (trendR != null && trendR.Length != 0)
                    {
                        decimal[][] maxSpotsMR = new decimal[2][];
                        maxSpotsMR[0]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        maxSpotsMR[0][0] = trendR[0][0];
                        maxSpotsMR[0][1] = allLinesMR.Max();
                        maxSpotsMR[1]    = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        maxSpotsMR[1][0] = trendR[trendR.Length - 1][0];
                        maxSpotsMR[1][1] = allLinesMR.Max();

                        json["MaxSpotsMR"] = maxSpotsMR;
                    }
                    #endregion

                    #region MR图最小值的点
                    if (trendR != null && trendR.Length != 0)
                    {
                        decimal[][] minSpotsMR = new decimal[2][];
                        minSpotsMR[0]      = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        minSpotsMR[0][0]   = trendR[0][0];
                        minSpotsMR[0][1]   = allLinesMR.Min();
                        minSpotsMR[1]      = (decimal[])Array.CreateInstance(typeof(decimal), 2);
                        minSpotsMR[1][0]   = trendR[trendR.Length - 1][0];
                        minSpotsMR[1][1]   = allLinesMR.Min();
                        json["MinSpotsMR"] = minSpotsMR;
                    }
                    #endregion
                }
                #endregion

                json["DicR"] = dicR;
                #endregion
                json["ChartCreater"] = cc;

                return(Ok(json));
            }
            catch (Exception e)
            {
                json["Error"] = e.Message + "-" + e.StackTrace;
                return(Ok(json));
            }
        }