2016-10-03 4 views

Antwort

0

Nach 2 Tagen finde ich endlich die Antwort aus. Die Sache ist, Sie können das Attribut value nicht ändern, aber Sie können das Attribut Ihrer API ändern, sobald Sie abgerufen haben. Ich habe eine Schleife verwendet, nachdem ich die API abgerufen und das Attribut 'profit' durch value ersetzt habe, auf diese Weise habe ich das Diagramm erstellt. Ja, die Sache, die ich ignoriert habe, war die Verwendung von 'Variable' anstelle von 'Geltungsbereich'. Wenn Sie dieses Beispiel sehen, würden Sie verstehen, Example Here. Ich teile meinen Code Vielleicht hilft es auch jemand anderem.

unten Geben Sie ist meine Json-Array, die ich genannt tps.json

[ 
     { 
      "index": "1", 
      "variantoption": "fan-green", 
      "company": "sk fans", 
      "quantity": "650", 
      "profit": "78296", 
      "loss": "8457", 
      "year": "2016" 


     }, 
     { 
      "index": "2", 
      "variantoption": "fan-white", 
      "company": "al ahmed fans", 
      "quantity": "450", 
      "profit": "78296", 
      "loss": "8457", 
      "year": "2016" 

     }, 
     { 
      "index": "3", 
      "variantoption": "fan-purple", 
      "company": "asia fans", 
      "quantity": "350", 
      "profit": "78296", 
      "loss": "8457", 
      "year": "2016" 
     }, 
     { 
      "index": "4", 
      "variantoption": "fan-yellow", 
      "company": "falcon fans", 
      "quantity": "250", 
      "profit": "78296", 
      "loss": "8457", 
      "year": "2016" 
     } 
    ] 

und hier ist mein Controller

$http.get('js/tps.json').success(function (data) { 
     var chartdata = data; 

     var arrLength = chartdata.length; 
     console.log(arrLength); 

     for (var i = 0; i < arrLength; i++) { 
       if (chartdata[i]['profit'] && chartdata[i]['index']) { 
        chartdata[i].value = chartdata[i].profit; 
        delete chartdata[i].profit; 

        chartdata[i].label = chartdata[i].index; 
        delete chartdata[i].index; 
        console.log(chartdata); 
       } 
      } 
      console.log(chartdata); 

      FusionCharts.ready(function() { 
      var tps = new FusionCharts({ 
       type: 'column2d', 
       renderAt: 'chart-container', 
       width: '500', 
       height: '300', 
       dataFormat: 'json', 
       dataSource: { 
        "chart": { 
        "caption": "Monthly", 
        "xaxisname": "Month", 
        "yaxisname": "Revenue", 
        "numberprefix": "$", 
        "showvalues": "1", 
        "animation": "1" 
       }, 

        "data" : chartdata 
       } 

      }); 


      tps.render(); 

     }); 
    } 
    ); 

} 

-Bleiben dumm Aufenthalt hungrig

Verwandte Themen