示例#1
0
    public void BuildChart()
    {
        bool    hasTarget      = true;
        decimal currentValue   = 0;
        int     firstDayOfWeek = Artexacta.App.Configuration.Configuration.GetFirstDayOfWeek();
        decimal progress       = KPIBLL.GetKpiProgress(KpiId, CategoryId, CategoryItemId, firstDayOfWeek, ref hasTarget, ref currentValue);

        if (!hasTarget)
        {
            CurrentValueLiteral.Text  = currentValue.ToString(CultureInfo.InvariantCulture);
            CurrentValuePanel.Visible = true;
            return;
        }

        DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(ClientID)
                                             .InitChart(new Chart()
        {
            Type = ChartTypes.Gauge,
            PlotBackgroundColor = null,
            PlotBackgroundImage = null,
            PlotBorderWidth     = 0,
            PlotShadow          = false
        })
                                             .SetTitle(new Title()
        {
            Text = ""
        })
                                             .SetTooltip(new Tooltip()
        {
            ValueSuffix = "%"
        })
                                             .SetPane(new Pane()
        {
            StartAngle = -150,
            EndAngle   = 150,
            Background = new DotNet.Highcharts.Helpers.BackgroundObject[]
            {
                new DotNet.Highcharts.Helpers.BackgroundObject()
                {
                    BackgroundColor = new DotNet.Highcharts.Helpers.BackColorOrGradient(new DotNet.Highcharts.Helpers.Gradient()
                    {
                        LinearGradient = new int[] { 0, 0, 0, 1 },
                        Stops          = new object[, ]
                        {
                            { 0, "#FFF" },
                            { 1, "#333" }
                        }
                    }),
                    BorderWidth = new DotNet.Highcharts.Helpers.PercentageOrPixel(1),
                    OuterRadius = new DotNet.Highcharts.Helpers.PercentageOrPixel(109, true)
                },
                new DotNet.Highcharts.Helpers.BackgroundObject()
                {
                    BackgroundColor = new DotNet.Highcharts.Helpers.BackColorOrGradient(new DotNet.Highcharts.Helpers.Gradient()
                    {
                        LinearGradient = new int[] { 0, 0, 0, 1 },
                        Stops          = new object[, ]
                        {
                            { 0, "#FFF" },
                            { 1, "#333" }
                        }
                    }),
                    BorderWidth = new DotNet.Highcharts.Helpers.PercentageOrPixel(1),
                    OuterRadius = new DotNet.Highcharts.Helpers.PercentageOrPixel(107, true)
                },
                new DotNet.Highcharts.Helpers.BackgroundObject()
                ,
                new DotNet.Highcharts.Helpers.BackgroundObject()
                {
                    BackgroundColor = new DotNet.Highcharts.Helpers.BackColorOrGradient(ColorTranslator.FromHtml("#DDD")),
                    BorderWidth     = new DotNet.Highcharts.Helpers.PercentageOrPixel(0),
                    OuterRadius     = new DotNet.Highcharts.Helpers.PercentageOrPixel(105, true),
                    InnerRadius     = new DotNet.Highcharts.Helpers.PercentageOrPixel(103, true)
                }
            }
        }).SetYAxis(new YAxis()
        {
            Min = 0,
            Max = 100,

            MinorTickWidth    = 1,
            MinorTickLength   = 10,
            MinorTickPosition = TickPositions.Inside,
            MinorTickColor    = ColorTranslator.FromHtml("#666"),

            TickPixelInterval = 30,
            TickWidth         = 2,
            TickPosition      = TickPositions.Inside,
            TickLength        = 10,
            TickColor         = ColorTranslator.FromHtml("#666"),

            Labels = new YAxisLabels()
            {
                Step = 2
            },
            Title = new YAxisTitle()
            {
                Text = "%"
            },
            PlotBands = new YAxisPlotBands[]
            {
                new YAxisPlotBands()
                {
                    From  = 0,
                    To    = 33,
                    Color = ColorTranslator.FromHtml("#DF5353")
                },
                new YAxisPlotBands()
                {
                    From  = 33,
                    To    = 66,
                    Color = ColorTranslator.FromHtml("#DDDF0D")
                },
                new YAxisPlotBands()
                {
                    From  = 66,
                    To    = 100,
                    Color = ColorTranslator.FromHtml("#55BF3B")
                }
            }
        })
                                             .SetSeries(new Series()
        {
            Name = Resources.KpiDetails.CompleteLabel,
            Data = new DotNet.Highcharts.Helpers.Data(new object[] { progress })
        });
        ChartLiteral.Text = chart.ToHtmlString();
    }