Ejemplo n.º 1
0
        public Highcharts TransBasicCol()
        {
            SMSServersEntities tp = new SMSServersEntities();
            List <Series>      sr = new List <Series>();

            foreach (var sp in tp.spVotePartyTransPie().ToList())
            {
                sr.Add(new Series {
                    Name = sp.Abrev, Data = new Data(new object[] { Math.Round(sp.Total, 2) })
                });
            }

            Highcharts chart1 = new Highcharts("chart1")
                                .InitChart(new Chart {
                DefaultSeriesType = ChartTypes.Column
            })
                                .SetTitle(new Title {
                Text = "Total votes per party"
            })
                                .SetSubtitle(new Subtitle {
                Text = "Summary: National"
            })
                                .SetXAxis(new XAxis {
                Categories = new[] { "National" }
            })
                                .SetYAxis(new YAxis
            {
                Min   = 0,
                Title = new YAxisTitle {
                    Text = "Votes (%)"
                }
            })
                                .SetLegend(new Legend
            {
                Layout          = Layouts.Vertical,
                Align           = HorizontalAligns.Left,
                VerticalAlign   = VerticalAligns.Top,
                X               = 100,
                Y               = 70,
                Floating        = true,
                BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")),
                Shadow          = true
            })
                                .SetTooltip(new Tooltip {
                Formatter = @"function() { return ''+ this.series.name +': '+ this.y +' %'; }"
            })
                                .SetPlotOptions(new PlotOptions
            {
                Column = new PlotOptionsColumn
                {
                    PointPadding = 0.2,
                    BorderWidth  = 0
                }
            })
                                .SetSeries(sr.ToArray());

            return(chart1);
        }
Ejemplo n.º 2
0
        public Highcharts PieData()
        {
            List <ZoneData>    data  = new List <ZoneData>();
            SMSServersEntities tp    = new SMSServersEntities();
            string             tDate = DateTime.Today.ToString("MM/dd/yyyy");

            var tran = tp.spVotePartyTransPie().OrderBy(c => c.Abrev);

            foreach (var iTra in tran.ToList())
            {
                data.Add(new ZoneData {
                    ZoneName = iTra.Abrev, Total = (decimal)Math.Round(iTra.Total, 2)
                });
            }
            object[,] chartData = new object[data.Count, 2];
            int i = 0;

            foreach (ZoneData item in data)
            {
                chartData.SetValue(item.ZoneName, i, 0);
                chartData.SetValue(item.Total, i, 1);
                i++;
            }

            Data dt = new Data(chartData);

            Highcharts chart = new Highcharts("chart")
                               .InitChart(new Chart {
                PlotShadow = false
            })
                               .SetTitle(new Title {
                Text = String.Format("Shares of votes as at {0}", DateTime.Now)
            })
                               .SetTooltip(new Tooltip {
                Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(2) +' %'; }"
            })
                               .SetPlotOptions(new PlotOptions
            {
                Pie = new PlotOptionsPie {
                    AllowPointSelect = true, Cursor = Cursors.Pointer, DataLabels = new PlotOptionsPieDataLabels {
                        Color = ColorTranslator.FromHtml("#000000"), ConnectorColor = ColorTranslator.FromHtml("#000000"), Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %'; }"
                    }
                },
            })
                               .SetSeries(new Series
            {
                Type = ChartTypes.Pie,
                Name = "Browser share",
                Data = dt
            });

            return(chart);
        }