admin

从ASP.net SQL数据库检索数据到amchart

sql

我面临一个相当大的问题,那就是从http://www.amcharts.com/创建漂亮的图形,但是我需要从我的sql数据库中检索数据。但是我不知道如何放置在里面。请指导我。下面是图形显示的方式,但是我想使用数据库中的数据。谢谢你。

<script type="text/javascript">

        var chartData = generateChartData();

        function generateChartData() {
            var chartData = [];
            var firstDate = new Date(2012, 0, 1);
            firstDate.setDate(firstDate.getDate() - 500);
            firstDate.setHours(0, 0, 0, 0);

            for (var i = 0; i < 500; i++) {
                var newDate = new Date(firstDate);
                newDate.setDate(newDate.getDate() + i);

                var value = Math.round(Math.random() * (40 + i)) + 100 + i;

                chartData.push({
                    date: newDate,
                    value: value
                });
            }
            return chartData;
        }


        AmCharts.makeChart("chartdiv", {

            type: "stock",

            pathToImages: "../amcharts/images/",

            dataSets: [{
                color: "#b0de09",
                fieldMappings: [{
                    fromField: "value",
                    toField: "value"
                }],
                dataProvider: chartData,
                categoryField: "date"
            }],

            panels: [{
                showCategoryAxis: true,
                title: "Value",
                eraseAll: false,
                labels: [{
                    x: 0,
                    y: 100,
                    text: "Click on the pencil icon on top-right to start drawing",
                    align: "center",
                    size: 16
                }],

                stockGraphs: [{
                    id: "g1",
                    valueField: "value",
                    bullet: "round",
                    bulletColor: "#FFFFFF",
                    bulletBorderColor: "#00BBCC",
                    bulletBorderAlpha: 1,
                    bulletBorderThickness: 2,
                    bulletSize: 7,
                    lineThickness: 2,
                    lineColor: "#00BBCC",
                    useDataSetColors: false
                }],


                stockLegend: {
                    valueTextRegular: " ",
                    markerType: "none"
                },

                drawingIconsEnabled: true
            }],

            chartScrollbarSettings: {
                graph: "g1"
            },
            chartCursorSettings: {
                valueBalloonsEnabled: true
            },
            periodSelector: {
                position: "bottom",
                periods: [{
                    period: "DD",
                    count: 10,
                    label: "10 days"
                }, {
                    period: "MM",
                    count: 1,
                    label: "1 month"
                }, {
                    period: "YYYY",
                    count: 1,
                    label: "1 year"
                }, {
                    period: "YTD",
                    label: "YTD"
                }, {
                    period: "MAX",
                    label: "MAX"
                }]
            }
        });
    </script>

阅读 136

收藏
2021-07-01

共1个答案

admin

您能在后面的代码中生成此脚本吗(例如,使用字符串生成器),然后使用此脚本

ScriptManager.RegisterStartupScript(this, this.GetType(), "", "'" + YourStringBuild.toString() + "'", true);
2021-07-01