c# - LINQ SQL Method not Filling Highcharts -
my goal create column highchart shows name of various salesman , how have sold. wrote code return sql database names , sum of sales each salesman:
[httppost] public jsonresult chartvendedores() { //retorna um json contendo o nome vendedor e o valor por ele vendido, usando inner join pelo id vendedor. try { var resultado = (from ve in db.tblvendedor join vn in db.tblvenda on ve.vendedor_id equals vn.vendedor_id group vn new { ve.vendedor_nome }into g select new { vendedor_nome = g.key.vendedor_nome, venda_valor = g.sum(x => x.venda_valor) }).tolist(); var jsonresult = new { nomes = resultado.select(x => x.vendedor_nome), valores = resultado.select(x => x.venda_valor) }; return json(resultado); }catch(exception) { return null; } }
and chart created, method called , suposed fill chart database's return data:
<script> $(function () { $.ajax({ url: '/vendedores/chartvendedores', type: 'post', async: false, sucess: function (data) { //constrói o gráfico com os valores retornados pelo banco. highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'venda dos colaboradores' }, xaxis: { categories: [ data.nomes ], crosshair: true }, yaxis: { min: 0, title: { text: 'valor (r$)' } }, tooltip: { headerformat: '<span style="font-size:10px">{point.key}</span><table>', pointformat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerformat: '</table>', shared: true, usehtml: true }, plotoptions: { column: { pointpadding: 0.2, borderwidth: 0 } }, series: [{ name: 'valores', data: data.valores }] }); } }) })
what i'm missing? long code goes, don't think wrote wrong code in method. calling wrong? manipulating wrong? tried remove ajax code, leaving chart on highchart.com , worked, problem not on container div or in chart code.
edit: commented bellow, looked @ console , i'm getting warning 1 of imports highcharts needs. waning follows is one. after seeing this, tried remove ajax , using highchart code. worked! reason when chart tries use this:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
it not find when chart code contained inside sucess: function(data){}
note: i'm importing @ beggining of code, meanwhile script containing ajax written last.
$.ajax({ url: '/vendedores/chartvendedores', type: 'post', async: false, sucess: function (data) {
should changed to:
$.ajax({ url: '/vendedores/chartvendedores', type: 'post', async: false, success: function (data) {
you have misspelt success
.
Comments
Post a Comment