You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2018/08/16 02:16:24 UTC

[GitHub] wqqwqq666 opened a new issue #8877: echarts 4.0 动态设置dataset DataSource

wqqwqq666 opened a new issue #8877: echarts 4.0 动态设置dataset DataSource
URL: https://github.com/apache/incubator-echarts/issues/8877
 
 
   <!--
   为了方便我们能够复现和修复 bug,请遵从下面的规范描述您的问题。
   -->
   
   
   ### 根据Ajax 请求得到dataset 中source的数据源
   
   `前端代码:                   
   ```
               $.ajax({
                   type: "post",
                   url: "/Test/eChartsData",
                   dataType: "json",
                   async: false, //同步执行
                   success: function (result) {
                       //var test = $.parseJSON(result.data);
                       myChart.setOption({
                           legend: {},
                           tooltip: {},
                           dataset: {
                               dimensions: ['WorkDate', 'OutputByStaff'],
                               source: [result]
                               //dimensions: ['product', '2015'],
                               //source: [
                               //    { product: 'Matcha Latte', '2015': 43.3, '2016': 85.8, '2017': 93.7 },
                               //    { product: 'Milk Tea', '2015': 83.1, '2016': 73.4, '2017': 55.1 },
                               //    { product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5 },
                               //    { product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1 }
                               //]
                           },
                           grid: { containLabel: true },
                           xAxis: { type: 'category' },
                           yAxis: {},
                           series: [
                               {
                                   datasetIndex: 0,
                                   type: 'bar',
                                   //encode: {
                                   //    // 将 "amount" 列映射到 X 轴。
                                   //    x: 'WorkDate',
                                   //    // 将 "product" 列映射到 Y 轴。
                                   //    y: 'OutputByStaff'
                                   //}
                               }
                           ]
                       });
   
                       var test3 = myChart.getOption();
                       //test3.dataset.source = test;
                       //test3.dataset.dimensions = ['WorkDate', 'OutputByStaff'];
                       //test3.series[0].encode.x = 'WorkDate';
                       // test3.series[0].encode.y = 'OutputByStaff';
                       myChart.setOption(test3);
                   },
                   error: function (errorMsg) {
                       //alert(errorMsg);
                   }
               });
   
   ```
   如果采用官网的静态数据源显示数据没有问题,我已经注释了,但是从控制器获取到的Json 数组放到source里面 图表就不显示。
   这是后台返回的Json 数组,.NET:
   ```
               DataTable tb1 = ds.Tables[0];
               List<object> list = new List<object>();
               foreach (DataRow dr in tb1.Rows)
               {
                   var obj = new { WorkDate = dr["WorkDate"], OutputByStaff = dr["OutputByStaff"] };
                   list.Add(obj);
               }
               return Json(list, JsonRequestBehavior.AllowGet);
   ```
   Ajax中result返回值是一个Json数组,就是不显示,我以前都是用这个方法用在echarts 3.x 上,没有任何问题。求帮忙,dataset虽方便,不会用太。。。
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@echarts.apache.org
For additional commands, e-mail: dev-help@echarts.apache.org