2016-05-27 9 views
0

私は剣道図を使ってトレンドラインを描画している列の1つのグリッドを持っています。 問題はグラフが行の1つにしか表示されず、ページをリフレッシュするとグラフの行の位置が変わることがあります。時には全く表示されない(スクリーンショットが添付されています) 私は試しましたユニークなdivIdを渡し、ユニークなチャート名は運がないjavascript関数に渡します。私が見つからない唯一のものは、Javascript関数からJsRenderへの返信文です。私は剣道として返すことができません。 ここに私のJsRenderがあります。コードとJavascriptヘルパー機能。また、トレンドラインのスクリーンショットも含まれています。JSRender + Javascript関数を使用した剣道

script id="customGridTemplate" type="text/x-jsrender"> 
<div class="table-wrapper dashboard-grid" id="main"> 
    {^{for data)}} 
    {{!-- Get Column Headers --}} 
    {{if #getIndex() == 0}} 
    <div class="table-head"> 
     {{props}} 
     {{for key}} 
     <div class="table-col"> 
      <div class="table-th">{{:}}</div> 
     </div> 
     {{/for}} 
     {{/props}} 
    </div> 
    {{/if}} 
    {{/for}} 
    {^{for data}} 
    <div class="table-row"> 
     {{!-- Get Rows --}} 
     {{props}} 
     {{for}} 

     <div class="table-col"> 
      <div class="table-th">{{if key=='' || key == null}} &nbsp;{{else}} {{>key}} {{/if}}</div> 
      <div class="table-td"> 
       {{if #getIndex() == 0}} 
       <img title="Summary" id="displaySummary" data-link="name{:prop}" src="/Images/InfoImgIcon.png" alt="" height="16" width="14" /> 
       {{if prop=='' || prop == null}} &nbsp; {{else}} {{:prop}} {{/if}} 
       {{else key=='Trend'}} 
      <div id="Mydiv">{{:~trend('Mydiv',#parent.parent.data)}}</div> 
       </div> 
       {{else key=='Status'}} 
       {{if prop=='-1'}} <div><img title="" id="imgSquare" src="/Images/square.svg" alt="" height="16" width="14" /></div> {{/if}} 
       {{if prop=='0'}} <div><img title="" id="imgTriangle" src="/Images/triangle.svg" alt="" height="16" width="14" /></div> {{/if}} 
       {{if prop=='1'}} <div><img title="" id="imgCircle" src="/Images/circle.svg" alt="" height="16" width="14" /></div> {{/if}} 
       {{else}} 
       {{if prop=='' || prop == null}} &nbsp; {{else}} {{:prop}} {{/if}}{{/if}} 
      </div> 
      <div class="clear"></div> 
     </div> 

     {{/for}} 
     {{/props}} 

    </div> 
    {{/for}}  
     </div>  

      <div class="modal fade" data-link="id{:~WidgetId}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
       <div class="modal-dialog modal-lg"> 
        <div class="modal-content"> 
         <div class="modal-header"> 
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
          <h4 class="modal-title" id="myModalLabel">Metric Summary</h4> 
         </div> 
         <div class="modal-body"> 
          <table class=" table table-striped table-condensed"> 
           <tbody> 
            <tr> 
             <td width="65%"> 
              <table width="100%"> 
               <tbody> 
                <tr> 
                 <td colspan="2"> 
                  <table> 
                   <tbody> 
                    <tr><td>Metric Definition:&nbsp;</td><td> {{:Summary.MetricDefinition}}</td></tr> 
                    <tr><td>Metric Owner:&nbsp;</td><td>{{:Summary.MetricOwner}}</td></tr> 
                   </tbody> 
                  </table> 
                 </td> 
                </tr> 
                <tr style="border-bottom: 1px solid #E8E8E8"><td colspan="2"></td></tr> 
                <tr> 
                 <td width="32%"> 
                  <ul type="square" style="color:#5cb85c"><li><span style="color:#000000">Highlights:</span></li></ul> 
                  {{for Summary}} 
                  {{props CommentaryHighlights}} 
                  {{>prop}}<br /> 
                  {{/props}} 
                  {{/for}} 
                 </td> 
                 <td width="32%"> 
                  <ul type="square" style="color: #d9534f;"><li><span style="color:#000000">Lowlights:</span></li></ul> 
                  {{for Summary}} 
                  {{props CommentaryLowlights}} 
                  {{>prop}}<br /> 
                  {{/props}} 
                  {{/for}} 
                 </td> 
                </tr> 
               </tbody> 
              </table> 
             </td> 
             <td width="35%" height="100%"> 
              <div><table><tbody><tr><td>Graph Filter</td><td> 
                          <select name="cars"> 
                           <option value="YoY">YoY</option> 
                           <option value="MoM">MoM</option>                          
                          </select> 
               </td></tr></tbody></table></div> 
              <div style="border: 1px solid #E8E8E8; height: 200px;"> 
               <div id="chart"></div> 
              </div> 

             </td> 
            </tr> 
           </tbody> 
          </table> 
         </div> 
         <div class="modal-footer"> 
          <button type="button" id="btnClose" class="btn btn-default" data-dismiss="modal">Close</button> 
         </div> 
        </div> 
       </div> 
      </div> 

--------終了JSRenderスニペット-----------

---------- Beging HelperFunctionトレンド------ここ

function BindTrendLineChart(TrendDivId, MetricTrendData) { 
[![enter image description here][1]][1] 
var trendLineDataSource = TrendLineDataSource(MetricTrendData) 
$("#" + TrendDivId).kendoChart({ 
    dataSource: { 
     data: trendLineDataSource, 
     group: { 
      field: "data" 
     } 
    }, 
    series: [{   
     type: "line", 
     field: "value", 
     style: "smooth", 
     markers: { 
      visible: false 
     } 
    }], 
    categoryAxis: { 
     title: { 
      text: "" 
     }, 
     majorGridLines: { 
      visible: false 
     }, 
     majorTicks: { 
      visible: false 
     } 
    }, 
    valueAxis: { 
     max: 3, 
     title: { 
      text: "voltage" 
     }, 
     majorGridLines: { 
      visible: false 
     }, 
     visible: false 
    }, 
    chartArea: { 
     width: 100, 
     height: 30 
    }, 
    legend: { 
     position: "custom", 
     orientation: "horizontal", 
     visible: false 
    } 
}); 

}

答えて

0

問題は、あなたのアカウントにJsViewsの処理モデルを取っていないことです。 {{:~trend('Mydiv',#parent.parent.data)}}ヘルパー関数は、テンプレートのレンダリング中に呼び出されます(link(...)メソッドの最初の段階です)。それ以降はレンダリングされた出力がDOMに挿入されます。だから、

あなたは、単にであなたのコード内でJavaScriptのブレークポイントを入れていた場合:あなたはnull$("#" + TrendDivId)戻っていることがわかります$("#" + TrendDivId).kendoChart({... - その<div>はまだDOMに存在しないため。

正しいことは、データリンクが行われた後にグラフをレンダリングすることです。そのためには、剣道のJsViewsタグコントロールを定義し、タグコントロールのonAfterLinkハンドラでチャートのレンダリングを行います。あなたはこのようなあなたのテンプレートで使用することができ

// Define a kendochart tag 
$.views.tags("kendochart", { 
    onAfterLink: function(tagCtx, linkCtx) { 
    // Bind to the data-linked element, and pass the data argument 
    $(linkCtx.elem).kendoChart(tagCtx.args[0]); 
    } 
}); 

<div data-link="{kendochart chartdata}"></div> 

ここでは実施例である:https://jsfiddle.net/BorisMoore/uvcrvepL/

+0

あなたにボリスをありがとう!自分のコードを自分のコードベースに統合しましたが、データグリッドの最初の行のチャートレンダリングと同じ問題が残っています – user2048598

+0

私は – user2048598

+0

の上に更新されたコードを追加しましたが、テンプレートに '{kendochart} '

{{:~trend(#parent.parent.parent....}}
'を '
'などと置き換え、 'link(...)'を呼び出す前に 'chartdata'などでアプリケーションオブジェクトを定義する必要があります。 '〜trend(...) 'ヘルパーはまったく必要ありません... – BorisMoore

0

DrillDownGrid.Cshtml

<script id="customGridTemplate" type="text/x-jsrender"> 

<div class="table-wrapper dashboard-grid" id="main"> 
    {^{for data)}} 
    {{!-- Get Column Headers --}} 
    {{if #getIndex() == 0}} 
    <div class="table-head"> 
     {{props}} 
     {{for key}} 
     <div class="table-col"> 
      <div class="table-th">{{:}}</div> 
     </div> 
     {{/for}} 
     {{/props}} 
    </div> 
    {{/if}} 
    {{/for}} 
    {^{for data}} 
    <div class="table-row"> 
     {{!-- Get Rows --}} 
     {{props}} 
     {{for}} 
     <div class="table-col"> 
      <div class="table-th">{{if key=='' || key == null}} &nbsp;{{else}} {{>key}} {{/if}}</div> 
      <div class="table-td"> 
       {{if #getIndex() == 0}} 
       <img title="Summary" id="displaySummary" data-link="name{:prop}" src="/Images/InfoImgIcon.png" alt="" height="16" width="14" /> 
       {{if prop=='' || prop == null}} &nbsp; {{else}} {{:prop}} {{/if}} 
       {{else key=='Trend'}} 
       <div> 

        <div id="Content">{{:~trend(#parent.parent.parent.parent.data.MetricId,#parent.parent.data)}}</div> 

---- ------------------------------ End Snippet ------------------ ------------------

Drilldowngrid.js:

function BindTrendLineChart(TrendDivId, MetricTrendData) { 
debugger; 
var app = { 
    chartdata: { 
     title: "", 
     seriesDefaults: { 
      type: "line", 
      style: "smooth" 
     }, 
     series: [ 
      { name: "Example Series", data: [.20, .30, .40, .50, .60, .70, .70, .70, .70, 1] } 
     ], 
     categoryAxis: { 
      title: { 
       text: "" 
      }, 
      majorGridLines: { 
       visible: false 
      }, 
      majorTicks: { 
       visible: false 
      } 
     }, 
     valueAxis: { 
      max: 3, 
      title: { 
       text: "voltage" 
      }, 
      majorGridLines: { 
       visible: false 
      }, 
      visible: false 
     }, 
     chartArea: { 
      width: 100, 
      height: 30 
     }, 
     legend: { 
      position: "custom", 
      orientation: "horizontal", 
      visible: false 
     } 
    } 
}; 

$.views.tags("kendochart", { // Define a kendochart tag 
    onAfterLink: function (tagCtx, linkCtx) { 
     $(linkCtx.elem).kendoChart(tagCtx.args[0]); // Bind to the data-linked element 
    } 
}); 
$.link.theTmpl("#Content", app); 

}

関連する問題