0

我在 ASP.NET 中使用 jquery 饼图。饼图工作正常,但我想绑定数据库中的值。如何在饼图中绑定数据库值。我在数据库中创建了一个表,我想从数据库中获取值到饼图中。

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Highcharts Example</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function ()
        {
            var chart;
            $(document).ready(function ()
            {
                // Radialize the colors
                Highcharts.getOptions().colors = $.map(Highcharts.getOptions().colors, function (color)
                {
                    return {
                        radialGradient: {
                            cx: 0.5,
                            cy: 0.3,
                            r: 0.7
                        },
                        stops: [
                            [0, color],
                            [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
                        ]
                    };
                });
                // Build the chart
                chart = new Highcharts.Chart(
                {
                    chart: {
                        renderTo: 'container',
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: 'Browser market shares at a specific website, 2010'
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                        percentageDecimals: 1
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                connectorColor: '#000000',
                                formatter: function ()
                                {
                                    return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
                                }
                            }
                        }
                    },
                    series: [
                        {
                            type: 'pie',
                            name: 'Browser share',
                            data: [
                                ['Firefox', 45.0],
                                ['IE', 26.8],
                                {
                                    name: 'Chrome',
                                    y: 12.8,
                                    sliced: true,
                                    selected: true
                                }, ['Safari', 8.5],
                                ['Opera', 6.2],
                                ['Others', 0.7]
                            ]
                        }
                    ]
                });
            });
        });
    </script>
</head>

<body>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
    <di v id="container" style="min-width: 400px; height: 400px; margin: 0 auto">
        </div>
</body>

4

1 回答 1

0

简单的解决方案是将数据库中的值放在隐藏字段中,然后使用 javascript 访问它们并获取它们的值以用作系列的一部分。这是 ASPX:

....
 <asp:HiddenField ID="FireFoxDataValueFromDB" runat="server" />
 <asp:HiddenField ID="IEDataValueFromDB" runat="server" />
....

这是CS:

Page_Load Event()
{
    if (!IsPostBack)
    {
        FireFoxDataValueFromDB = getFFDBValue();
        IEDataValueFromDB = getIEDBValue
    }
}
....

这是Javascript:

var FFVal = $("#FireFoxDataValueFromDB").val();
var IEVal = $("#IEDataValueFromDB").val();

and then use it as the series data:
 series: [
                        {
                            type: 'pie',
                            name: 'Browser share',
                            data: [
                                ['Firefox', FFVal],
                                ['IE', IEVal],
                                {
                                    name: 'Chrome',
                                    y: 12.8,
                                    sliced: true,
                                    selected: true
                                }, ['Safari', 8.5],
                                ['Opera', 6.2],
                                ['Others', 0.7]
                            ]
                        }...
于 2013-04-03T10:22:21.260 回答