用数据库中的数据填充高图表的最佳(简单)方法

Best (easy) way to fill highcharts with data from database?

本文关键字:简单 方法 最佳 填充 数据库 数据 高图表      更新时间:2023-09-26

情况非常简单。我有一个VB.NET中的web应用程序。在某些页面中,我使用数据库中的数据生成报表。在同一个页面上,我需要从数据库中生成一个具有相同数据的图表。我正在使用一个简单的折线图和HighCharts.js

我只需要用数据库中的数据填充高图javascript

查看下方的代码

 $(function () {
        $('#container').highcharts({
            title: {
                text: 'Feedbacks',
                x: -20 //center
            },
            subtitle: {
                text: 'Report',
                x: -20
            },
            xAxis: {
                categories: [ /* here I need to put data from data base */ ]
            },
            yAxis: {
                title: {
                    text: 'Total'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: [{
                name: 'Positive',
                data: [ /* here I need to put data from data base */ ]
            }, {
                name: 'Neutral',
                data: [ /* here I need to put data from data base */ ]
            }, {
                name: 'Negative',
                data: [ /* here I need to put data from data base */ ]
            }]
        });
    });

非常感谢您的支持!

您可以准备脚本,从数据库中获取数据并创建JSON,然后在高图中,您可以使用getJSON()并粘贴数据,如我们的示例所示:http://jsfiddle.net/usgxh/1/