绘制图表ajax动态URL从服务器端获取数据

时间:2022-12-04 15:52:11

As I see to the flot reference. they said,

正如我所看到的flot参考。他们说,

The plot function can also be used as a jQuery chainable property.

plot函数也可以用作jQuery可链接属性。

Is possible to define the flot chart to be like this?

可以将flot图表定义为这样吗?

var pid = '';
var kid = '';
var chartasset;

$(document).ready(function() {
 var optionchart = {
  series: {
   pie: {
    show: true,                
    label: {
     show:true,
     radius: 0.8,
     formatter: function (label, series) {                
      return '<div style="border:1px solid grey;font-size:8pt;text-align:center;padding:5px;color:white;">' + label + ' : ' + Math.round(series.percent) + '%</div>';
     },
     background: {
      opacity: 0.8,
      color: '#000'
     }
    }
   }
  }
 };

 chartasset = $('#chartasset').plot({
  "ajax" : {
   "url": "<?php echo site_url('Asset/chart_asset')?>?pid="+pid+"&kid="+kid,
   "type": "POST",
   "cache": false,
   "dataType": "json"
  }, optionchart}).data('plot');
});

I need to make the url dynamically change in another function, so I can use :

我需要让url在另一个函数中动态更改,所以我可以使用:

chartasset.ajax.url("<?php echo site_url('Asset/chart_asset')?>?pid="+pid+"&kid="+kid).load();

How can I use the flot chainable property to get the data, after I'm defining the flot? Sorry for my bad english

在我定义flot之后,如何使用flot chainable属性来获取数据?对不起,我的英语不好

1 个解决方案

#1


0  

No, you can not define the Flot chart like that. If you want to use AJAX, do it this way (result has to be in the right format):

不,你不能像那样定义Flot图表。如果你想使用AJAX,那就这样做(结果必须是正确的格式):

$.ajax({
    "url": "<?php echo site_url('Asset/chart_asset')?>?pid="+pid+"&kid="+kid,
    "type": "POST",
    "cache": false,
    "dataType": "json",
    success: function(result) {
        chartasset = $('#chartasset').plot(result, optionchart).data('plot');
    }
}

#1


0  

No, you can not define the Flot chart like that. If you want to use AJAX, do it this way (result has to be in the right format):

不,你不能像那样定义Flot图表。如果你想使用AJAX,那就这样做(结果必须是正确的格式):

$.ajax({
    "url": "<?php echo site_url('Asset/chart_asset')?>?pid="+pid+"&kid="+kid,
    "type": "POST",
    "cache": false,
    "dataType": "json",
    success: function(result) {
        chartasset = $('#chartasset').plot(result, optionchart).data('plot');
    }
}