2017-12-27 12 views
0

標準のVisual Studio 2017を使用しているWebサイトがあります。これは、ユーザーの設定に基づいてHighMapsにデータを表示するよう要求する単一のAPIを持つC# jQueryのUIから選択します。私のMacと同じくらい自分のWindowsマシンが大好きではないので、私は.Net Core 2.0を使ってみることにしました。私のWindowsラップトップは不要です。すべてが非常にうまくいった(Microsoftへの名誉)が、何らかの理由でAPIを呼び出すjQueryコードの場合、返されたデータは地図のようにプッシュされることはありません。.NETコアへの移行後、ハイマップの更新が中止されました

ここではjQueryコードが実行されます - alert()はJSONデータを表示しますが、マップには反映されません。必要に応じてHTMLやCSSを投稿できますが、今はheadセクションとscriptセクションが含まれています。

<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Great Locations</title> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> 
    <script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
    <script type="text/javascript" src="https://code.highcharts.com/maps/highmaps.js"></script> 
    <script type="text/javascript" src="https://code.highcharts.com/maps/modules/data.js"></script> 
    <script type="text/javascript" src="https://code.highcharts.com/mapdata/countries/us/us-all-all.js"></script> 
</head> 

そしてここでjQueryのコードです:

<script type="text/javascript"> 
    var climateSteps = [ 
     "Tropical", 
     "Semi-Arid", 
     "Desert", 
     "Humid", 
     "Mediterranean", 
     "Wet All Seasons", 
     "Wet Summer", 
     "Winter Snow", 
     "Polar"]; 

    var climateRange = "C08"; 

    $(function() { 
     $("#climate-slider .slider").slider({ 
      range: true, 
      min: 0, 
      max: 8, 
      values: [0, 8], 
      slide: function (event, ui) { 
       climateRange = "C" + ui.values[0].toString() + ui.values[1].toString(); 
       if (ui.values[0] == ui.values[1]) { 
        /* if user selected a single value (not a range), adjust text to fit */ 
        $(this).parent().children(".slider-range").text(climateSteps[ui.values[0]]); 
       } 
       else { 
        $(this).parent().children(".slider-range").text(climateSteps[ui.values[0]] + " to " + climateSteps[ui.values[1]]); 
       } 
      } 
     }) 
    }); 

    $.noConflict(); 
    tableResult = '[{"code":"us-al-001","name":"Autauga County, AL","value":1}, {"code":"us-il-019","name":"Champaign County, IL","value":3}]'; 

    (function ($) { 
     function GetCounties(userSelections) { 
      jQuery.support.cors = true; 
      $.ajax({ 
       url: "http://localhost:5000/api/products/" + userSelections, 
       type: "GET", 
       dataType: "json", 
       success: function (d) { 
        data = JSON.stringify(d); 
        alert("API data received: " + data) 
        tableResult = data; 
        $("#map-container").highcharts().series[0].update({ 
         data: JSON.parse(d) 
        }); 
       }, 
       error: function (d) { 
        alert("API found error: " + JSON.stringify(d)); 
       } 
      }); 
     } 

     jQuery(".button-submit").bind("click", { 
     }, function (e) { 
      GetCounties(climateRange); 
      }); 

     data = JSON.parse(tableResult); 

     var countiesMap = Highcharts.geojson(Highcharts.maps["countries/us/us-all-all"]); 
     var lines = Highcharts.geojson(Highcharts.maps["countries/us/us-all-all"], "mapline"); 

     // add state acronym for tooltip 
     Highcharts.each(countiesMap, function (mapPoint) { 
      var state = mapPoint.properties["hc-key"].substring(3, 5); 
      mapPoint.name = mapPoint.name + ", " + state.toUpperCase(); 
     }); 

     var options = { 
      chart: { 
       borderWidth: 1, 
       marginRight: 50 // for the legend 
      }, 

      exporting: { 
       enabled: false 
      }, 

      title: { 
       text: "My Great Locations" 
      }, 

      legend: { 
       layout: "vertical", 
       align: "right", 
       floating: true, 
       valueDecimals: 0, 
       valueSuffix: "", 
       backgroundColor: "white", 
       symbolRadius: 0, 
       symbolHeight: 0 
      }, 

      mapNavigation: { 
       enabled: false 
      }, 

      colorAxis: { 
       dataClasses: [{ 
        from: 1, 
        to: 1, 
        color: "#000099", 
        name: "Perfect!" 
       }, { 
        from: 2, 
        to: 2, 
        color: "#009999", 
        name: "Very Nice!" 
       }, { 
        from: 3, 
        to: 3, 
        color: "#00994c", 
        name: "Good Fit" 
       }] 
      }, 

      tooltip: { 
       headerFormat: "", 
       formatter: function() { 
        str = "Error"; 
        if (this.point.value == 1) { 
         str = "Perfect!"; 
        } 
        if (this.point.value == 2) { 
         str = "Very Nice!"; 
        } 
        if (this.point.value == 3) { 
         str = "Good Fit"; 
        } 
        return this.point.name + ": <b>" + str + "</b>"; 
       } 
      }, 
      plotOptions: { 
       mapline: { 
        showInLegend: false, 
        enableMouseTracking: false 
       } 
      }, 

      series: [{ 
       mapData: countiesMap, 
       data: data, 
       joinBy: ["hc-key", "code"], 
       borderWidth: 1, 
       states: { 
        hover: { 
         color: "#331900" 
        } 
       } 
      }, { 
       type: "mapline", 
       name: "State borders", 
       data: [lines[0]], 
       color: "black" 
      }] 
     }; 

     // Instanciate the map 
     $("#map-container").highcharts("Map", options); 

マップに表示されるすべては、私が(マップが正常に動作していることを示すために)ハードコード2つの郡です。 NuGetやSDK Dependenciesに追加する必要があるパッケージがあるのか​​どうか疑問に思っていますが、何が欠けているのか分かりません。そして、私はMac Visual Studioでコンソールを表示する方法を理解していないので、そこに何か手がかりがある場合、私はそれらを見ていません。

+0

コードに間違いがありますか? 'console.log(JSON.parse(d))'の出力は何ですか? –

+0

JSON.stringify(d)の出力は、スライダーの位置によって異なりますが、「[{"code": "us-al-001"、 "name": "Autauga County、AL"、 "value "" 3 "、"コード ":" us-al-003 "、" name ":" Baldwin County、AL "、" value ":3}、{" code " 3 "}" {"code": "us-al-007"、 "name": "Bibb County、AL"、 "value":3}] " - " Barbour County、AL " (実際はずっと長い)。私はMac Visual Studioを使ってコンソール出力を取得する方法を理解していません(スタックトレースを表示して間違っている場合を除きます)。 –

+0

コンソール出力パッドを表示する方法を知りましたが –

答えて

0

Highchartsサポートチームに感謝します。この問題の究極の答えは、Mac Visual Studio .Net Coreフレームワークが何らかの理由で、従来のVisual Studioを実行しているWindowsプラットフォームとは異なる動作をすることです。

私はネットのコアを搭載したMacのVisual Studioでこれを使用するために必要な - なし JSON.parse(D)が必要です。:ここでは私のために働いた答えである。これに代え

$("#map-container").highcharts().series[0].update({ 
    data: d 
}); 

は、どのWindowsが本格的なVisual Studio(コミュニティ版)に対応:

$("#map-container").highcharts().series[0].update({ 
    data: JSON.parse(d) 
}); 
+0

異なる結果(-type)を取得している場合は、「load」関数、つまり関数loadData(d){if typeof d === 'string'に 'd 'をラップしたい場合があります。JSON.parse(d) ;それ以外の場合はdを返します。 } ' - 中間行を' data:loadData(d) 'に置き換えます。それはどちらのOS /バージョンのVisual Studioでも動作するはずです。 – David

関連する問題