2011-03-12 32 views
0

我正在尝试构建我的第一张图表,我尽可能将我的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;              
    } 
+0

你在做asp.net mvc吗?使用asp.net-mvc标签,然后 – gideon 2011-03-13 07:55:45

回答

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

但在一般情况下,如果你有麻烦与highcharts,他们有great documentation解释每个配置选项和功能,以及JSFiddle的例子。

+0

我已经尝试过类似于此的东西,但是这不会拉动四季,我只是从0-9取代x轴。 – user517406 2011-03-13 11:02:29

+0

结果中实际存储了什么值[i]。季节。你确定他们是'92','93','94'等吗?或者他们是92,93,94,...? – NT3RP 2011-03-13 15:51:53

+0

我只是在玩一个[示例highcharts小提琴](http://jsfiddle.net/nt3r/CAKQH/9396/)。如果返回的数据是'92,93,94',我认为编辑应该修复一些东西('chart.xAxis [0] .setCategories(categories)') – NT3RP 2011-03-13 15:58:07

相关问题