0

最初のグラフを作成しようとしています。y 軸のデータを取得するところまでは到達しましたが、データ ソースから x 軸を作成する方法がまだわかりません。私の現在のコードは値をハード コードしていますが、これらの値は result[i].Season から取得する必要があります。これが私のコードです。誰か助けてもらえますか?

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;                                                     
    }
4

1 に答える 1

1

次のようにコードを変更することで、シリーズを設定できるはずです。

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();
    });
}

しかし、一般に、ハイチャートで問題が発生した場合は、JSFiddle の例とともに、利用可能なすべての構成オプションと機能を説明する優れたドキュメントがあります。

于 2011-03-13T07:54:04.990 に答える