1
我有了一個價值酒吧和一個線路一個值的谷歌組合圖,我也想一行顯示條的值的平均值,所以我找到了代碼會這樣做,但是,實施時我的另一條線消失了。谷歌圖表,均線刪除我的其他線路
這是我的圖表看起來像前。
這是我實現了平均線後,我的其他線消失。
我不知道該怎麼做才能讓他們既說明了什麼?
此行似乎與所有事情有關,將dv
更改回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>
哦,我試圖改變幾號在這裏和那裏不知道狗屎我在做什麼,但沒想到加一的!這工作,非常感謝你! –
歡呼!很高興幫助,隨時... – WhiteHat