Retrieving data from ASP.net sql database into amchart

放肆的年华 提交于 2019-12-24 05:07:41

问题


i am facing quite a problem which is to create the nice graph from http://www.amcharts.com/ but i need to retrieve data from my sql database. But i don't know how to place inside. Please guide me. Below is the way how the graph displayed, but i wanted to work with data from database. Thank you.

<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>

回答1:


Can you generate this script in your code behind ( using a string builder for example ) then use this

ScriptManager.RegisterStartupScript(this, this.GetType(), "", "'" + YourStringBuild.toString() + "'", true);


来源:https://stackoverflow.com/questions/20424962/retrieving-data-from-asp-net-sql-database-into-amchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!