weixin_33712881 2017-03-07 03:14 采纳率: 0%
浏览 18

我如何在这里使用for循环?

Hi I'm getting my data with ajax, they are coming with json so my code is this

$.ajax({
      async:true,
      type: "POST",
      dataType: "html",
      contentType: "application/x-www-form-urlencoded",
      url:"http://sosacelulares.com/index.php/chart/buygeneralreport",
      success: function(response) {
      var returnedData = JSON.parse(response);

The data looks like this

[{
  "id_buy_report":"1",
  "month":"1",
  "year":"2016",
  "total":"10"
},{
  "id_buy_report":"2",
  "month":"1",
  "year":"2017",
  "total":"20"
}]

Then I am trying to use that data to create a Pie Chart and the complete code is this:

 $.ajax({
      async:true,
      type: "POST",
      dataType: "html",
      contentType: "application/x-www-form-urlencoded",
      url:"http://sosacelulares.com/index.php/chart/buygeneralreport",
      success: function(response) {
      var returnedData = JSON.parse(response);

      var donutData = [
        {label: "Series2", data: 10},
        {label: "Series3", data: 40},
        {label: "Series4", data: 50}
      ];

      $.plot("#donut-chart", donutData, {
        series: {
          pie: {
            show: true,
            radius: 1,
            innerRadius: 0.5,
            label: {
              show: true,
              radius: 2 / 3,
              formatter: labelFormatter,
              threshold: 0.1
            }

          }
        },
        legend: {
          show: false
        }
      });

The problem is that my data are coming how you can see from a database and if i want to create the Pie Chart I need to put the data here..

var donutData = [
    {label: "Series2", data: 10},
    {label: "Series3", data: 40},
    {label: "Series4", data: 50}
  ];

It will create a pie chart with three portions, but it is static i need to put a (for loop) to allow the data create automaticly..

How can I make a for loop in that donutData code? any loop it's no necessary a for loop..I need just a loop that it allows me to fill donutData automaticly. Thanks

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 如何降低hdfs中datanode的JVM内存用量
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver