2017-07-14 12 views
0

Ich versuche, Bild von Highchart-Export-Modul zu erhalten, und es gibt Bild mit Diagramm Eingabedaten Fehler, Syntaxfehler: Unerwartete EOF.Highcharts Export-Modul geben Fehler

Bitte Code in dieser js Geige sehen.

http://jsfiddle.net/GopinathGD/3xy8aeb7/

$(function() { 
    $("#b").click(testPOST); 

    var exportUrl = 'http://export.highcharts.com/'; 

    function testPOST() { 

     var dataStr= { 
      "colors": [ 
       "#C00000" 
      ], 
      "chart": { 
       "type": "bar" 
      }, 
      "title": { 
       "text": "Current Analysis Competitive Index", 
       "style": { 
        "fontWeight": "bold", 
        "color": "rgba(164, 0, 31, 0.96)" 
       } 
      }, 
      "subtitle": { 
       "text": "Source: © 2017 Current Analysis, Inc." 
      }, 
      "xAxis": { 
       "tickWidth": 1, 
       "minPadding": 0, 
       "maxPadding": 0, 
       "categories": [ 
        "Overall", 
        "Vision/Strategy", 
        "Momentum & Stability", 
        "Innovation", 
        "Product Portfolio", 
        "Go-to-Market", 
        "Service & Support" 
       ], 
       "title": { 
        "text": null 
       }, 
       "labels": { 
        "style": { 
         "color": "#000000", 
         "fontWeight": "bold", 
         "fontSize": "12px" 
        } 
       } 
      }, 
      "yAxis": { 
       "min": 0, 
       "max": 10, 
       "tickInterval": 1, 
       "tickmarkPlacement": "off", 
       "categories": [ 
        "", 
        "Vulnerable", 
        "", 
        "Competitive", 
        "", 
        "Strong", 
        "", 
        "Very Strong", 
        "", 
        "Leader", 
        "" 
       ], 
       "title": { 
        "text": "", 
        "align": "high" 
       }, 
       "labels": { 
        "style": { 
         "color": "#000000", 
         "fontWeight": "bold", 
         "fontSize": "12px" 
        } 
       } 
      }, 
      "plotOptions": { 
       "bar": { 
        "dataLabels": { 
         "enabled": false 
        }, 
        "pointpadding": 0, 
        "groupPadding": 0 
       }, 
       "series": { 
        "animation": false, 
        "pointWidth": 9, 
        "pointPadding": 0, 
        "groupPadding": 0.1 
       } 
      }, 
      "legend": { 
       "margin": 30 
      }, 

      "series": [ 
       { 
        "name": "BlackBerry - Consumer Platforms and Devices", 
        "data": [ 
         3, 
         3, 
         3, 
         3, 
         2, 
         6, 
         6 
        ] 
       } 
      ] 
     }; 
     var optionsStr = JSON.stringify(dataStr), 
     dataString = encodeURI('async=true&options='+optionsStr+'&type=jpeg&width=400'); 

     if (window.XDomainRequest) { 
      var xdr = new XDomainRequest(); 
      xdr.open("post", exportUrl+ '?' + dataString); 
      xdr.onload = function() { 
       console.log(xdr.responseText); 
       $('#container').html('<img src="' + exporturl + xdr.responseText + '"/>'); 
      }; 
      xdr.send(); 
     } else { 
      $.ajax({ 
       type: 'POST', 
       data: dataString, 
       url: exportUrl, 
       success: function (data) { 
        console.log('get the file from relative url: ', data); 
        $('#container').html('<img src="' + exportUrl + data + '"/>'); 
       }, 
       error: function (err) { 
        debugger; 
        console.log('error', err.statusText) 
       } 
      }); 
     } 

    } 
}); 


<script src="http://code.highcharts.com/highcharts.js"></script> 

Run-Code

Antwort

1

Der Grund ist, zwei in den xAxis.categories verwendet Et-Zeichen.

"categories": [ 
    "Momentum & Stability", 
    ... 
    "Service & Support" 
], 

ändern Et-Zeichen zu %26

"categories": [ 
      "Overall", 
      "Vision/Strategy", 
      "Momentum %26 Stability", 
      "Innovation", 
      "Product Portfolio", 
      "Go-to-Market", 
      "Service %26 Support" 
     ], 

einen Rückruf schaffen, die Et-Zeichen codiert (auf dem Server Rückruf aufgerufen wird):

function callback() { 
     const categories = this.xAxis[0].categories.map(decodeURIComponent) 
     this.xAxis[0].setCategories(categories) 
    } 

den Rückruf Datenzeichen anhängen:

dataString = encodeURI('async=true&options='+optionsStr+'&type=jpeg&width=400&callback=' + callback.toString()); 

Beispiel: http://jsfiddle.net/erayy8jn/