public BackColorOrGradient(Gradient gradient)
 {
     Gradient = gradient;
 }
        /// <summary>
        /// Builds the high chart for Throughput chart
        /// </summary>
        /// <param name="tpCurveClean">TP curve clean</param>
        /// <param name="tpCurveNoClean">TP curve no clean</param>
        /// <param name="isDashboard">IsDashboard flag</param>
        /// <returns>Returns the high chart</returns>
        private Highcharts plotTPData(Dictionary<DateTime, Tuple<int, double, string>> tpCurveClean, Dictionary<DateTime, Tuple<int, double, string>> tpCurveNoClean, bool isDashboard)
        {
            try
            {
                double cleanAverage = 0;
                double noCleanAverage = 0;
                double xaxisMinValue = 0.0;
                double xaxisMaxValue = Convert.ToDouble(tpCurveClean.Last().Value.Item1);
                List<Point> replacePts = new List<Point>();
                List<Point> cleanedPts = new List<Point>();
                List<double> xseries = new List<double>();
                double[] chartdata1 = new double[tpCurveClean.Count];
                double[] chartdata2 = new double[tpCurveNoClean.Count];
                Point[] chartData_Point1 = new Point[tpCurveClean.Count];
                Point[] chartData_Point2 = new Point[tpCurveNoClean.Count];
                int counter = 0;
                Number width, height;
                foreach (DateTime dateTime in tpCurveClean.Keys)
                {
                    Tuple<int, double, string> tuple = tpCurveClean[dateTime];
                    chartData_Point1[counter] = new Point();
                    chartData_Point1[counter].X = tuple.Item1;
                    chartData_Point1[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    chartdata1[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    xseries.Add(tuple.Item1);
                    counter++;
                    if (tuple.Item3 == "Clean")
                    {
                        cleanedPts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 });
                    }
                }
                Number? MaximumWeek = chartData_Point1 != null && chartData_Point1.Length > 0 ? chartData_Point1[chartdata1.Count() - 1].X : 0;

                cleanAverage = chartdata1.Length > 0 ? chartdata1.Average() : 0;
                counter = 0;
                if (isDashboard == true)
                {
                    width = 500;
                    height = 290;
                }
                else
                {
                    width = 650;
                    height = 300;
                }
                foreach (DateTime dateTime in tpCurveNoClean.Keys)
                {
                    Tuple<int, double, string> tuple = tpCurveNoClean[dateTime];
                    chartData_Point2[counter] = new Point();
                    chartData_Point2[counter].X = tuple.Item1;
                    chartData_Point2[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    chartdata2[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    counter++;
                    if (tuple.Item3 == "Replace")
                    {
                        replacePts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 });
                    }
                }
                noCleanAverage = chartdata2.Length > 0 ? chartdata2.Average() : 0;
                xaxisMinValue = xseries.Count > 0 ? xseries[0] : 0;

                // Set up area color fill gradient parameters
                Gradient gradLine = new Gradient();
                int[] LinearGradient = new int[] { 0, 0, 0, 300 };
                gradLine.LinearGradient = LinearGradient;
                object[,] stops2 = new object[,] { { 0, "#F7EF9B" }, { 1, "#FFFFFF" } };
                gradLine.Stops = stops2;

                Series withCleaning = new Series
                {
                    Name = "With Cleaning",
                    Data = new Data(chartData_Point1),
                    PlotOptionsArea = new PlotOptionsArea
                    {
                        FillColor = new BackColorOrGradient(Color.FromArgb(30, 0, 128, 0)),
                        Color = Color.FromArgb(80, 153, 80)
                    }
                };

                Series withoutCleaning = new Series
                {
                    Name = "Without Cleaning",
                    Data = new Data(chartData_Point2),
                    PlotOptionsArea = new PlotOptionsArea
                    {
                        FillColor = new BackColorOrGradient(gradLine),
                        Color = System.Drawing.Color.Goldenrod
                    }
                };
                Highcharts chart1 = new Highcharts("chart")
                    .SetOptions(new GlobalOptions
                    {
                        Lang = new DotNet.Highcharts.Helpers.Lang { ThousandsSep = ",", DecimalPoint = "." }
                    })
                   .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Area, ZoomType = ZoomTypes.X, SpacingRight = 20 })
                   .SetTitle(new Title { Text = "Throughput Forecast" })
                   .SetTooltip(new Tooltip
                   {
                       HeaderFormat = "<b>Week: {point.x:.0f}</b><br>",
                       //PointFormat = "<b><span style=\"color:this.data.marker.fillcolor\">{series.name}: {point.y:,.2f}</b></span><br>",

                       // Use javascript function to control the tool tip coloring, to add a week number display, and to add thousands place seperartors
                       Formatter = @"function() {var s = [];var X = '';$.each(this.points, function(index,point){if((index%2)==0){s.push('<span style=""color:#E6B800;font-weight:bold;"">'+ point.series.name + ' : <span>' + '<b style=""font-weight:bold;"">' + point.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, "","") + '</b>');}else{s.push('<span style=""color:#509950;font-weight:bold;"">'+ point.series.name + ' : <span>' + '<b style=""font-weight:bold;"">' + point.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, "","") + '</b>');}X = point.x;});var header = '<span style=""font-weight:bold;"">Week: ' + X.toString() + '<span>';  s.splice(0, 0, header); var temp1 = s[1];var temp2 = s[2];s[1] = temp2;s[2] = temp1;if(s.length >= 5){temp1 = s[4];temp2 = s[3];s[4] = temp2;s[3] = temp1;}return s.join('<br>');}",
                       Enabled = true,
                       Shared = true
                   })
                   .SetXAxis(new XAxis
                   {
                       Title = new XAxisTitle { Text = "Number of Weeks" },
                       Type = AxisTypes.Linear,
                       MinRange = 0,
                       Min = xaxisMinValue,
                       Max = xaxisMaxValue,
                       TickInterval = 20,
                       Labels = new XAxisLabels { Formatter = "function() { return this.value;  }" }
                   })
                   .SetCredits(new Credits { Enabled = false })
                   .SetLegend(new Legend
                    {
                        BorderWidth = 1,
                    })
                   .SetYAxis(new YAxis
                   {
                       Title = new YAxisTitle { Text = "Throughput" },
                       Labels = new YAxisLabels { Formatter = "function() { return this.value; }" }
                   })
                   .SetPlotOptions(new PlotOptions
                   {
                       Area = new PlotOptionsArea
                       {
                           Marker = new PlotOptionsAreaMarker
                           {
                               Enabled = false,
                               Symbol = "circle",
                               Radius = 2,
                               States = new PlotOptionsAreaMarkerStates
                               {
                                   Hover = new PlotOptionsAreaMarkerStatesHover { Enabled = true }
                               }
                           },
                           PointInterval = 1,
                           PointStart = new PointStart(xaxisMinValue),
                       }
                   })
                   .SetSeries(new[] {  withoutCleaning, withCleaning,
                   new Series
                   {
                       Name = "Replace",
                       Type = ChartTypes.Scatter,
                       Data = new Data(replacePts.ToArray()),
                       Color = Color.Blue,
                   },
                   new Series
                   {
                       Name = "Clean",
                       Type = ChartTypes.Scatter,
                       Data = new Data(cleanedPts.ToArray()),
                       Color = Color.Red
                   },
                   new Series
                   {
                       Name = "Without Cleaning Average",
                       Type = ChartTypes.Spline,
                       Data = new Data(new[] { new Point
                                                       {
                                                           X = xaxisMinValue,
                                                           Y = noCleanAverage,
                                                       },
                                                       new Point
                                                       {
                                                           X = MaximumWeek,
                                                           Y = noCleanAverage,
                                                       }
                                                   }),
                       Color = Color.Goldenrod
            ,
                       PlotOptionsSpline=new PlotOptionsSpline
                       {
                           DashStyle=DashStyles.ShortDash,
                           LineWidth=1,
                           Marker = new PlotOptionsSplineMarker{Enabled = false},
                       }
                     },
                     new Series
                   {
                       Name = "With Cleaning Average",
                       Type = ChartTypes.Spline,
                       Data = new Data(new[] { new Point
                                                       {
                                                           X = xaxisMinValue,
                                                           Y = cleanAverage,
                                                       },
                                                       new Point
                                                       {
                                                           X = MaximumWeek,
                                                           Y = cleanAverage,
                                                       }
                                                   }),
                       Color = Color.ForestGreen,
                       PlotOptionsSpline=new PlotOptionsSpline
                       {
                           DashStyle=DashStyles.ShortDash,
                           LineWidth=1,
                           Marker = new PlotOptionsSplineMarker{Enabled = false}
                       }
                     }
                   }
                );
                return chart1;
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
 public BackColorOrGradient(Gradient gradient)
 {
     Gradient = gradient;
 }
        /// <summary>
        /// Builds the high chart for Throughput chart
        /// </summary>
        /// <param name="tpCurveClean">TP curve clean</param>
        /// <param name="tpCurveNoClean">TP curve no clean</param>
        /// <param name="isDashboard">IsDashboard flag</param>
        /// <returns>Returns the high chart</returns>
        private Highcharts plotTPData(Dictionary<DateTime, Tuple<int, double, string>> tpCurveClean, Dictionary<DateTime, Tuple<int, double, string>> tpCurveNoClean, bool isDashboard)
        {
            try
            {
                double cleanAverage = 0;
                double noCleanAverage = 0;
                double xaxisMinValue = 0.0;
                double xaxisMaxValue = Convert.ToDouble(tpCurveClean.Last().Value.Item1);
                List<Point> replacePts = new List<Point>();
                List<Point> cleanedPts = new List<Point>();
                List<double> xseries = new List<double>();
                double[] chartdata1 = new double[tpCurveClean.Count];
                double[] chartdata2 = new double[tpCurveNoClean.Count];
                Point[] chartData_Point1 = new Point[tpCurveClean.Count];
                Point[] chartData_Point2 = new Point[tpCurveNoClean.Count];
                int counter = 0;
                Number width, height;
                foreach (DateTime dateTime in tpCurveClean.Keys)
                {
                    Tuple<int, double, string> tuple = tpCurveClean[dateTime];
                    chartData_Point1[counter] = new Point();
                    chartData_Point1[counter].X = tuple.Item1;
                    chartData_Point1[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    chartdata1[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    xseries.Add(tuple.Item1);
                    counter++;
                    if (tuple.Item3 == "Clean")
                    {
                        cleanedPts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 });
                    }
                }
                Number? MaximumWeek = chartData_Point1 != null && chartData_Point1.Length > 0 ? chartData_Point1[chartdata1.Count() - 1].X : 0;

                cleanAverage = chartdata1.Length > 0 ? chartdata1.Average() : 0;
                counter = 0;
                if (isDashboard == true)
                {
                    width = 500;
                    height = 290;
                }
                else
                {
                    width = 650;
                    height = 300;
                }
                foreach (DateTime dateTime in tpCurveNoClean.Keys)
                {
                    Tuple<int, double, string> tuple = tpCurveNoClean[dateTime];
                    chartData_Point2[counter] = new Point();
                    chartData_Point2[counter].X = tuple.Item1;
                    chartData_Point2[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    chartdata2[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0;
                    counter++;
                    if (tuple.Item3 == "Replace")
                    {
                        replacePts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 });
                    }
                }
                noCleanAverage = chartdata2.Length > 0 ? chartdata2.Average() : 0;
                xaxisMinValue = xseries.Count > 0 ? xseries[0] : 0;

                // Set up area color fill gradient parameters
                Gradient gradLine = new Gradient();
                int[] LinearGradient = new int[] { 0, 0, 0, 300 };
                gradLine.LinearGradient = LinearGradient;
                object[,] stops2 = new object[,] { { 0, "#F7EF9B" }, { 1, "#FFFFFF" } };
                gradLine.Stops = stops2;

                Series withCleaning = new Series
                {
                    Name = "With Cleaning",
                    Data = new Data(chartData_Point1),
                    PlotOptionsArea = new PlotOptionsArea
                    {
                        FillColor = new BackColorOrGradient(Color.FromArgb(30, 0, 128, 0)),
                        Color = Color.FromArgb(80, 153, 80)
                    }
                };

                Series withoutCleaning = new Series
                {
                    Name = "Without Cleaning",
                    Data = new Data(chartData_Point2),
                    PlotOptionsArea = new PlotOptionsArea
                    {
                        FillColor = new BackColorOrGradient(gradLine),
                        Color = System.Drawing.Color.Goldenrod
                    }
                };
                Highcharts chart1 = new Highcharts("chart")
                    .SetOptions(new GlobalOptions
                    {
                        Lang = new DotNet.Highcharts.Helpers.Lang { ThousandsSep = ",", DecimalPoint = "." }
                    })
                   .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Area, ZoomType = ZoomTypes.Xy, SpacingRight = 20 })
                   .SetTitle(new Title { Text = "Throughput Forecast" })
                   .SetTooltip(new Tooltip
                   {
                       HeaderFormat = "<b>Week: {point.x:.0f}</b><br>",
                       PointFormat = "<b>{series.name}: {point.y:,.2f}</b><br>",
                       Enabled = true,
                       Shared = true
                   })
                   .SetXAxis(new XAxis
                   {
                       Title = new XAxisTitle { Text = "Number of Weeks" },
                       Type = AxisTypes.Linear,
                       MinRange = xaxisMinValue,
                       Min = xaxisMinValue,
                       Max = xaxisMaxValue,
                       TickInterval = 20,
                       Labels = new XAxisLabels { Formatter = "function() { return this.value;  }" }
                   })
                   .SetCredits(new Credits { Enabled = false })
                   .SetLegend(new Legend
                   {
                       BorderWidth = 1,
                   })
                   .SetYAxis(new YAxis
                   {
                       Title = new YAxisTitle { Text = "Throughput" },
                       Labels = new YAxisLabels { Formatter = "function() { return this.value; }" }
                   })
                   .SetPlotOptions(new PlotOptions
                   {
                       Area = new PlotOptionsArea
                       {
                           Marker = new PlotOptionsAreaMarker
                           {
                               Enabled = false,
                               Symbol = "circle",
                               Radius = 2,
                               States = new PlotOptionsAreaMarkerStates
                               {
                                   Hover = new PlotOptionsAreaMarkerStatesHover { Enabled = true }
                               }
                           },
                           PointInterval = 1,
                           PointStart = new PointStart(xaxisMinValue),
                       }
                   })
                   .SetSeries(new[] {  withoutCleaning, withCleaning,
                   new Series
                   {
                       Name = "Replace",
                       Type = ChartTypes.Scatter,
                       Data = new Data(replacePts.ToArray()),
                       Color = Color.Blue,
                   },
                   new Series
                   {
                       Name = "Clean",
                       Type = ChartTypes.Scatter,
                       Data = new Data(cleanedPts.ToArray()),
                       Color = Color.Red
                   },
                   new Series
                   {
                       Name = "Without Cleaning Average",
                       Type = ChartTypes.Spline,
                       Data = new Data(new[] { new Point
                                                       {
                                                           X = xaxisMinValue,
                                                           Y = noCleanAverage,
                                                       },
                                                       new Point
                                                       {
                                                           X = MaximumWeek,
                                                           Y = noCleanAverage,
                                                       }
                                                   }),
                       Color = Color.Goldenrod
            ,
                       PlotOptionsSpline=new PlotOptionsSpline
                       {
                           DashStyle=DashStyles.ShortDash,
                           LineWidth=1,
                           Marker = new PlotOptionsSplineMarker{Enabled = false},
                       }
                     },
                     new Series
                   {
                       Name = "With Cleaning Average",
                       Type = ChartTypes.Spline,
                       Data = new Data(new[] { new Point
                                                       {
                                                           X = xaxisMinValue,
                                                           Y = cleanAverage,
                                                       },
                                                       new Point
                                                       {
                                                           X = MaximumWeek,
                                                           Y = cleanAverage,
                                                       }
                                                   }),
                       Color = Color.ForestGreen,
                       PlotOptionsSpline=new PlotOptionsSpline
                       {
                           DashStyle=DashStyles.ShortDash,
                           LineWidth=1,
                           Marker = new PlotOptionsSplineMarker{Enabled = false}
                       }
                     }
                   }
                );
                return chart1;
            }
            catch (Exception)
            {
                throw;
            }
        }