열 차트를 생성하기 위해 googlecharts 플러그인을 사용하고 있습니다.테이블의 td 안에있는 값의 평균을 계산하는 jQuery
또한 td에있는 값의 평균을 얻고 싶습니다. 그것은 구글 차트 플러그인을 통해 가능하거나 누군가가 평균을 계산하는 서면 ajquery에서 나를 도울 수 있습니다. 평균을 계산 한 후에 단락 태그에 "avg"클래스를 추가해야합니다. 도움 주셔서 감사합니다.
<table id="weather">
<thead>
<tr>
<th></th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
</tr>
</thead>
<tbody>
<tr>
<th>Weather</th>
<td>20</td>
<td>22</td>
<td>18</td>
<td>24</td>
<td>20</td>
<td>22</td>
</tr>
</tbody>
</table>
그리고 자바 스크립트 코드 :
내 코드는
<script type="text/javascript">
gvChartInit();
$(document).ready(function(){
$('#weather').gvChart({
chartType: 'ColumnChart',
gvSettings: {
width: 100,
height: 40,
colors:['gray'],
hAxis: {textPosition: 'none'},
vAxis: {minValue: 0, textPosition: 'none', gridlines: {color: '#ffffff'}},
legend: {position: 'none'}
}
});
</script>
는 평균 와서해야합니다 별도로 VAR 평균 = 0과 같은 변수 변수를 선언; var amount = 0; 그런 다음 함수에서 0을 제거합니다. 즉 avg + = + ($ (this) .text())로 만듭니다. 마지막으로 작동합니다. 고마워. –