2011-03-12 5 views
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;              
    } 
+0

asp.net mvc 하시겠습니까? asp.net-mvc 태그를 사용하십시오. – gideon

답변

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

그러나 일반적으로

, 혹시 문제가있는 경우 하이 차트의 경우에는 great documentation이 있으며 JSFiddle 예제와 함께 사용 가능한 모든 구성 옵션과 기능을 설명합니다.

+0

나는 이미 이와 비슷한 것을 시도해 봤지만, Season을 통과하지는 않습니다. 대신 x 축을 0-9에서 얻습니다. – user517406

+0

실제로 어떤 값이 results [i] .Season에 저장됩니다. '92', '93', '94'등이 맞습니까? 아니면 92, 93, 94, ...입니까? – NT3RP

+0

나는 [example highcharts fiddles] (http://jsfiddle.net/nt3r/CAKQH/9396/) 중 하나를 가지고 놀고 있었다. 반환 된 데이터가 '92, 93, 94 '인 경우 수정 사항을 수정해야한다고 생각합니다 ('chart.xAxis [0] .setCategories (categories)') – NT3RP

관련 문제