System::Windows::Forms::WebBrowser 型のオブジェクトを含む Windows デスクトップ アプリケーションで作業しています。アプリケーションはいくつかのパフォーマンス データを処理し、さまざまなグラフ (ヒストグラム、円グラフなど) を含む HTML ページを表示します。
次のように機能します。
- アプリケーションは、ローカル一時パス (例: .../local/path/myfile.html) に HTML ファイルを生成します。
アプリケーションの WebBrowser オブジェクトは、生成されたファイルに移動します。
webBrowser1->Navigate(".../local/path/myfile.html")
jQuery とその他のプラグイン (jqPlot など) を使用してさまざまなグラフを作成し、アプリケーション内で myfile.html をレンダリングします。
myfile.html にはコードのセクションが含まれています。
<div id="frame-time-histograms">
<div id="frame-time-histogram-1">
<div id="frame-time-histogram-1-target-plot" class="histogram-target" style="height:250px; width:900px;"></div>
<div id="frame-time-histogram-1-controller-plot" class="histogram-controller" style="height:100px; width:900px;"></div>
<script id="frame-time-histogram-1-data" class="histogram-data" type="text/plain">
[{"type" : "Type 1", "shortest" : 12, "longest" : 74}, [[0, 0], [1, 12.632], [2, 16.619], [3, 16.592], [4, 16.664], [5, 16.586]]]
</script>
</div>
<div id="frame-time-histogram-2">
<div id="frame-time-histogram-2-target-plot" class="histogram-target" style="height:250px; width:900px;"></div>
<div id="frame-time-histogram-2-controller-plot" class="histogram-controller" style="height:100px; width:900px;"></div>
<script id="frame-time-histogram-2-data" class="histogram-data" type="text/plain">
[{"type" : "Type 2", "shortest" : 24, "longest" : 19}, [[0, 0], [1, 20.145], [2, 20.091], [3, 20.301], [4, 20.109], [5, 20.087]]]
</script>
</div>
</div>
注: ここでは、スクリプト タグをヒストグラムのデータ コンテナーとして使用しています。
私の JavaScript ファイルには、コードのセクションが含まれています。
var histograms = $('div#frame-time-histograms');
histograms.children().each(function(index) {
var histogramTargetId = $(this).find('div.histogram-target').attr('id');
var histogramControllerId = $(this).find('div.histogram-controller').attr('id');
var histogramData = JSON.parse($(this).find('script.histogram-data').html());
ただし、 JSON.parse() は何もしていないようです。この行の前後に alert("hello") を追加しましたが、最初の行だけが実行されます。
一時パスに移動して myfile.html をダブルクリックすると、JSON.parse() が正常に動作します。Web ブラウザー (Chrome、FF、IE) ですべてのグラフを表示できます。
私が間違っていることを誰かに教えてもらえますか?