Exemplo n.º 1
0
        public HttpResponseMessage Highchart([FromUri]string format = "JSON", [FromUri]string type = "1")
        {
            try
            {
                if (!User.Identity.IsAuthenticated) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified.")); }
                if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"]))); }
                //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); }

                // You would modify what gets returned here to make it meaningful
                var retVal = new GeckoHighchart()
                {
                    Chart = new HighchartChart()
                    {
                        RenderTo = "container",
                        PlotBackgroundColor = "rgba(35,37,38,0)",
                        BackgroundColor = "rgba(35,37,38,100)",
                        BorderColor = "rgba(35,37,38,100)",
                        PlotBorderColor = "rgba(35,37,38,100)",
                        PlotShadow = false,
                        Height = 170
                    },
                    Colors = new List<string>() { "#058DC7", "#50B432", "#EF561A" },
                    Credits = new HighchartCredits() { Enabled = false },
                    Title = new HighchartTitle() { Text = "test" },
                    //Tooltip = new HighchartTooltip() { Formatter = System.Web.HttpUtility.JavaScriptStringEncode("") }
                    Legend = new HighchartLegend()
                    {
                        BorderColor = "rgba(35,37,38,100)",
                        ItemWidth = 55,
                        Margin = 5,
                        Width = 200
                    },
                    PlotOptions = new HighchartPlotOptions()
                    {
                        PieOptions = new HighchartPieOptions()
                        {
                            Animation = true,
                            AllowPointSelect = true,
                            Cursor = "pointer",
                            DataLabelOptions = new HighchartDataLabelOptions() { Enabled = false },
                            ShowInLegend = true,
                            Size = "100%"
                        }
                    },
                    Series = new List<HighchartSeries>()
                    {
                        new HighchartSeries(){
                            Type = "pie",
                            Name = "New vs Returning",
                            Data = new List<Dictionary<string, int>>()
                            {
                                new Dictionary<string, int>(){{"Free",13491}},
                                new Dictionary<string, int>(){{"Premium",191}}
                            }
                        }
                    }

                };

                return this.Request.CreateResponse<GeckoHighchart>(HttpStatusCode.OK, retVal);
            }
            catch (Exception ex)
            {
                return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Highchart([FromUri] string format = "JSON", [FromUri] string type = "1")
        {
            try
            {
                if (!User.Identity.IsAuthenticated)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified.")));
                }
                if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"]))));
                }
                //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); }

                // You would modify what gets returned here to make it meaningful
                var retVal = new GeckoHighchart()
                {
                    Chart = new HighchartChart()
                    {
                        RenderTo            = "container",
                        PlotBackgroundColor = "rgba(35,37,38,0)",
                        BackgroundColor     = "rgba(35,37,38,100)",
                        BorderColor         = "rgba(35,37,38,100)",
                        PlotBorderColor     = "rgba(35,37,38,100)",
                        PlotShadow          = false,
                        Height = 170
                    },
                    Colors = new List <string>()
                    {
                        "#058DC7", "#50B432", "#EF561A"
                    },
                    Credits = new HighchartCredits()
                    {
                        Enabled = false
                    },
                    Title = new HighchartTitle()
                    {
                        Text = "test"
                    },
                    //Tooltip = new HighchartTooltip() { Formatter = System.Web.HttpUtility.JavaScriptStringEncode("") }
                    Legend = new HighchartLegend()
                    {
                        BorderColor = "rgba(35,37,38,100)",
                        ItemWidth   = 55,
                        Margin      = 5,
                        Width       = 200
                    },
                    PlotOptions = new HighchartPlotOptions()
                    {
                        PieOptions = new HighchartPieOptions()
                        {
                            Animation        = true,
                            AllowPointSelect = true,
                            Cursor           = "pointer",
                            DataLabelOptions = new HighchartDataLabelOptions()
                            {
                                Enabled = false
                            },
                            ShowInLegend = true,
                            Size         = "100%"
                        }
                    },
                    Series = new List <HighchartSeries>()
                    {
                        new HighchartSeries()
                        {
                            Type = "pie",
                            Name = "New vs Returning",
                            Data = new List <Dictionary <string, int> >()
                            {
                                new Dictionary <string, int>()
                                {
                                    { "Free", 13491 }
                                },
                                new Dictionary <string, int>()
                                {
                                    { "Premium", 191 }
                                }
                            }
                        }
                    }
                };

                return(this.Request.CreateResponse <GeckoHighchart>(HttpStatusCode.OK, retVal));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }