2014-09-02 75 views
0

我想從一個劍道餅圖去一個劍道條形圖,我的問題是條形圖只返回一塊數據。劍道餅圖到條形圖

CSHTML `

<div id="pieEmployeeContainer"> 
    @(Html.Kendo().Chart<SalesChart>().Name("pieEmployee").HtmlAttributes(new { style = "width: 90%;", @class = "fpos-chart" }) 
     .Title("Top 10") 
     .Legend(false) 
     .Theme("bootstrap") 
       .DataSource(ds => ds.Read("SM_GetSalesByEmployees", "Home")) 
     .Series(s => s 
      .Pie(m => m.Total, m => m.Category) 
      .Padding(0) 
     ) 

     .Tooltip(t => t 
      .Visible(true) 
      .Format("{0:c}") 
      .Template("#= category # <br /> #= kendo.format('{0:c}', value) # (#= kendo.format('{0:p}', percentage)#)") 
     ) 

     .Events(e => e.SeriesClick("getByEmployee")) 
     .Deferred() 
    ) 
</div> 

`

控制器

 public ActionResult SM_GetSalesByEmployees() 
    { 
     List<SalesChart> items; 
     List<SalesChart> salesByEmpl; 

     using (StreamReader r = new StreamReader("C:\\Development\\Back Office Web\\Sandbox\\BackOffice.Web\\BackOffice.Web\\Content\\Data\\SalesByEmployee.json")) 
     { 
      string json = r.ReadToEnd(); 
      items = JsonConvert.DeserializeObject<List<SalesChart>>(json); 
      salesByEmpl = items.GroupBy(l => l.EmployeeName) 
         .Select(lg => 
          new SalesChart 
          { 
           Category = lg.Key,          
           Total = lg.Sum(w => w.Total)          
          }).ToList(); 
     } 
     return new CustomJsonResult 
     { 
      Data = salesByEmpl 
     }; 
    } 
    script 
     function getByEmployee(e) 
    { 
     var categorySelected = e.category; 
     var chart = $("#pieEmployee").data("kendoChart"); 
     $.post("Home/GetSalesByEmployee?EmpName=" + categorySelected, function (results) { 
      chart.setDataSource(new kendo.data.DataSource({ data: results })); 
     }); 

     chart.options.series[0].type = "bar"; 
     chart.options.series[0].ValueAxis = "${Total}"; 
     chart.options.series[0].categoryAxis = "{Category}"; 
     chart.options.categoryAxis.baseUnit = "months"; 
     chart.refresh(); 
    } 

我沒有一個足夠好的口碑,發佈圖片,很抱歉。 條形圖僅獲取一個數據點並顯示,而不是顯示所有數據。 任何幫助,不勝感激。

回答

0

我不能建立任何測試的東西,但從快速查看它,餅圖的數據格式需要改變。它需要百分比(整個系列需要= 100),因此您需要在視圖或控制器中轉換數據。