简体   繁体   English

浮点图ajax动态url从服务器端获取数据

[英]Flot chart ajax dynamic url getting data from server side

As I see to the flot reference . 正如我所看到的浮点参考 they said, 他们说,

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? 可以这样定义浮点图吗?

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? 定义flot之后,如何使用flot的可链接属性获取数据? Sorry for my bad english 对不起,我的英语不好

No, you can not define the Flot chart like that. 不,您不能像这样定义Flot图表。 If you want to use AJAX, do it this way ( result has to be in the right format ): 如果要使用AJAX,请按以下方式进行操作( result必须采用正确的格式 ):

$.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');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM