2017-02-10 9 views
1

棒グラフと線分の値が1つのGoogleコンボチャートがあります。棒の値の平均値を表示したいので、見つけました。しかし、それを行うコードは、私の他の行が実装されたとき消えた。Googleグラフ、平均線が私の他の線を削除する

これは私のグラフが以前のように見えるものです。

enter image description here

そして、私は平均線を実装した後、これは、私の他の行が消えました。

enter image description here

私はそれらの両方のショーにするために行う方法がわかりませんか?

この行には、すべてをdataに変更すると、最初の画像でどのように表示されているかがわかりますが、変更する必要があります?

chart.draw(dv, options); 

ここにコードがあります。

<script> 
    google.charts.load('current', { 
     'packages': ['corechart'] 
    }); 
    google.charts.setOnLoadCallback(drawVisualization); 


    function drawVisualization() { 
     var data = google.visualization.arrayToDataTable([ 
      ['Day', 'Repetitions', 'Sets'], 
      @foreach (var c in db.Query(Query, inputDate, endDate, baselift)) 
      { 
       var totAvg = c.avg; 
       var allReps = c.reps; 
       var realAvg = (totAvg/allReps) * 100; 

       //Writes out the data that will be shown in the chart. 
       <text>['@c.date', @c.reps, @c.sets],</text> 
      } 
     ]); 

      // Create a DataView that adds another column which is all the same (empty-string) to be able to aggregate on. 
      var viewWithKey = new google.visualization.DataView(data); 
        viewWithKey.setColumns([0, 1, { 
         type: 'string', 
         label: '', 
         calc: function (d, r) { 
          return '' 
         } 
        }]) 

        // Aggregate the previous view to calculate the average. This table should be a single table that looks like: 
        // [['', AVERAGE]], so you can get the Average with .getValue(0,1) 
        var group = google.visualization.data.group(viewWithKey, [2], [{ 
         column: 1, 
         id: 'avg', 
         label: 'Average', 
         aggregation: google.visualization.data.avg, 
         'type': 'number' 
        }]); 

        // Create a DataView where the third column is the average. 
        var dv = new google.visualization.DataView(data); 
        dv.setColumns([0, 1, { 
         type: 'number', 
         label: 'Average', 
         calc: function (dt, row) { 
          return group.getValue(0, 1); 
         } 
        }]); 

        var options = {        
         title: 'Daily Repetition Statistics', 
         backgroundColor: { fill: 'transparent' }, 
         explorer: { axis: 'horizontal' }, 
         vAxes: { 

          0: { logScale: false, viewWindow: { min: 0 } }, 
          1: { logScale: false, maxValue: 2 } 

         }, 
         hAxis: { title: 'Day' }, 
         seriesType: 'bars', 
         curveType: 'function', 
         series: { 
         0: { 
           targetAxisIndex: 0, 
           color: 'orange'          
          }, 
         1: { targetAxisIndex: 1 }, 
         1: { targetAxisIndex: 1, type: "line" }, 
         2: { targetAxisIndex: 1, type: "line" } 
        } 
       }; 

       var chart = new google.visualization.ComboChart(document.getElementById('chart_div')); 
       chart.draw(dv, options); 
       } 
      </script> 

答えて

1

'sets'の列インデックスは

var dv = new google.visualization.DataView(data); 
dv.setColumns([0, 1, { 
    type: 'number', 
    label: 'Average', 
    calc: function (dt, row) { 
     return group.getValue(0, 1); 
    } 
}]); 

に...

var dv = new google.visualization.DataView(data); 
dv.setColumns([0, 1, 2, { // <-- add 'sets' column index 2 
    type: 'number', 
    label: 'Average', 
    calc: function (dt, row) { 
     return group.getValue(0, 1); 
    } 
}]); 
+0

ああ... setColumns

変更これに提供されていない、私はいくつかの数字を変更してみました私は何をしているのか分からず、1つを追加することを考えなかった!これはうまくいきました、ありがとう! –

+1

よろしく!いつでも助けてくれることをうれしく思います... – WhiteHat

関連する問題