Jquery 我的第一张海图

Jquery 我的第一张海图,jquery,asp.net-mvc,highcharts,Jquery,Asp.net Mvc,Highcharts,我正在尝试建立我的第一张图表,我已经得到了我的y轴数据,但我仍然不知道如何从我的数据源建立我的x轴。我当前的代码对中的值进行硬编码,但这些值应来自结果[i]。季节。这是我的密码,有人能帮忙吗 var chart; $(document).ready(function () { chart = new Highcharts.Chart({ chart: { renderTo: 'graphcontainer', def

我正在尝试建立我的第一张图表,我已经得到了我的y轴数据,但我仍然不知道如何从我的数据源建立我的x轴。我当前的代码对中的值进行硬编码,但这些值应来自结果[i]。季节。这是我的密码,有人能帮忙吗

var chart;

$(document).ready(function () {



    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'graphcontainer',
            defaultSeriesType: 'line',
            events: {
                load: requestData
            }
        },
        legend: {
            enabled: false
        },
        colors: [
            '#c9243f'
        ],
        credits: {
            enabled: false
        },
        title: {
            text: 'Regular Season Wins',

            style: {
                fontWeight: 'normal'
            }
        },
        xAxis: {
            categories: [
                        '92',
                        '93',
                        '94',
                        '09',
                        '10',
                        '11',
                        '12',
                        '13',
                        '14',
                        '15'
                    ],
            title: {
                text: 'Season'
            }
        },
        yAxis: {
            min: 0,
            max: 16,
            tickInterval: 2,
            title: {
                text: 'Games Won'
            }
        },
        tooltip: {
            formatter: function () {
                return '' +
                            this.x + ': ' + this.y + ' wins';
            }
        },
        series: [{ data: []}] 
    });
});

function requestData() 
{
    $.post('/Gameplan/Team/GetRegularSeasonWins', { strTeam: "Atlanta Falcons", strSeason: "2016" }, function (result) {

        $.each(result, function (i) {
            chart.series[0].addPoint(result[i].Wins, false);
        });

        chart.redraw();
    });
}
和我的数据访问:

public List<RegularSeasonWins> GetRegularSeasonWins(string strTeam, string strSeason)
    {
        List<RegularSeasonWins> lstRegularSeasonWins = new List<RegularSeasonWins>();

        lstRegularSeasonWins = (from w in _database.RegularSeasonWins(strTeam, strSeason)

                                select new RegularSeasonWins
                                {
                                    Team = w.Team,
                                    Coach = w.coach,
                                    Season = w.seasonshort,
                                    Wins = w.won
                                }).ToList();

        return lstRegularSeasonWins;                                                     
    }
public List GetRegularSeasonWins(字符串stream,字符串strSeason)
{
List lstRegularSeasonWins=新列表();
lstRegularSeasonWins=(来自_数据库中的w.regularalseasonwins(strTeam,strSeason)
选择新的常客
{
团队=w团队,
Coach=w.Coach,
季节,
Wins=w.won
}).ToList();
返回lstRegularSeasonWins;
}

您应该能够通过如下修改代码来设置序列:

function requestData() {
    $.post('/Gameplan/Team/GetRegularSeasonWins', {
        strTeam: "Atlanta Falcons",
        strSeason: "2016"
    }, function (result) {

        var categories = [];
        $.each(result, function (i) {
            chart.series[0].addPoint(result[i].Wins, false);

            categories.push(results[i].Season)
        });
        chart.xAxis[0].setCategories(categories);
        chart.redraw();
    });
}

但一般来说,如果你在使用highcharts时遇到问题,它们会解释所有可用的配置选项和函数,以及JSFIDLE示例。

你在使用asp.net mvc吗?使用asp.net-mvc标记,然后我已经尝试了类似的方法,但这并没有贯穿整个季节,我只是从0-9获得一个x轴。结果[I]中实际存储了哪些值。季节。你确定它们是“92”、“93”、“94”等吗。?或者他们是92,93,94,…?我只是在和其中一个玩。如果返回的数据是'92,93,94',我认为编辑应该会解决问题(
chart.xAxis[0].setCategories(categories)
)编辑工作正常…非常感谢,我花了很多时间试图找出我在这方面的错误!