리스트에서 차트가 다 안나옵니다
관련링크
본문
리스트에서 갤러리처럼 차트로 리스트를 구현할려고 합니다.
view 화면에서는 여분필드 수치를 인식해서 그래프가 잘 구현됩니다
그런데 리스트에서는 제일 최근에 올린 것만 나오고 나머지 차트리스트는 리스트에 나오지 않습니다
왜 이런지 봐줄 수있으면 정말 감사드리겠습니다
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<?php if ($is_checkbox) { ?>
<div id="gall_allchk">
<label for="chkall" class="sound_only">현재 페이지 게시물 전체</label>
<input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);">
</div>
<?php } ?>
<ul id="gall_ul" class="gall_row">
<?php for ($i=0; $i<count($list); $i++) {
$classes = array();
$classes[] = 'gall_li';
$classes[] = 'col-gn-'.$bo_gallery_cols;
if( $i && ($i % $bo_gallery_cols == 0) ){
$classes[] = 'box_clear';
}
if( $wr_id && $wr_id == $list[$i]['wr_id'] ){
$classes[] = 'gall_now';
}
?>
<li class="<?php echo implode(' ', $classes); ?>">
<div class="gall_box">
<div class="gall_chk">
<?php if ($is_checkbox) { ?>
<label for="chk_wr_id_<?php echo $i ?>" class="sound_only"><?php echo $list[$i]['subject'] ?></label>
<input type="checkbox" name="chk_wr_id[]" value="<?php echo $list[$i]['wr_id'] ?>" id="chk_wr_id_<?php echo $i ?>">
<?php } ?>
<span class="sound_only">
<?php
if ($wr_id == $list[$i]['wr_id'])
echo "<span class=\"bo_current\">열람중</span>";
else
echo $list[$i]['num'];
?>
</span>
</div>
<div class="gall_con">
<div class="gall_img">
<div style="width:250px">
<canvas id="myChart"></canvas>
</div>
<script>
// 우선 컨텍스트를 가져옵니다.
var ctx = document.getElementById("myChart").getContext('2d');
/*
- Chart를 생성하면서,
- ctx를 첫번째 argument로 넘겨주고,
- 두번째 argument로 그림을 그릴때 필요한 요소들을 모두 넘겨줍니다.
*/
var myChart = new Chart(ctx, {
type: 'radar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [<?=$list[$i][wr_1]?>, <?=$list[$i][wr_2]?>, <?=$list[$i][wr_3]?>, <?=$list[$i][wr_4]?>, <?=$list[$i][wr_7]?>, <?=$list[$i][wr_9]?>],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
maintainAspectRatio: true, // default value. false일 경우 포함된 div의 크기에 맞춰서 그려짐.
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
</script>
</div>
<div class="gall_text_href">
<?php
// echo $list[$i]['icon_reply']; 갤러리는 reply 를 사용 안 할 것 같습니다. - 지운아빠 2013-03-04
if ($is_category && $list[$i]['ca_name']) {
?>
<a href="<?php echo $list[$i]['ca_name_href'] ?>" class="bo_cate_link"><?php echo $list[$i]['ca_name'] ?></a>
<?php } ?>
<a href="<?php echo $list[$i]['href'] ?>" class="bo_tit">
<?php echo $list[$i]['subject'] ?>
<?php if ($list[$i]['comment_cnt']) { ?><span class="sound_only">댓글</span><span class="cnt_cmt">+ <?php echo $list[$i]['wr_comment']; ?></span><span class="sound_only">개</span><?php } ?>
<?php
// if ($list[$i]['link']['count']) { echo '['.$list[$i]['link']['count']}.']'; }
// if ($list[$i]['file']['count']) { echo '<'.$list[$i]['file']['count'].'>'; }
if (isset($list[$i]['icon_new'])) echo rtrim($list[$i]['icon_new']);
if (isset($list[$i]['icon_hot'])) echo rtrim($list[$i]['icon_hot']);
//if (isset($list[$i]['icon_file'])) echo rtrim($list[$i]['icon_file']);
//if (isset($list[$i]['icon_link'])) echo rtrim($list[$i]['icon_link']);
if (isset($list[$i]['icon_secret'])) echo rtrim($list[$i]['icon_secret']);
?>
</a>
</div>
</div>
</div>
</li>
<?php } ?>
답변 1
<div style="width:250px">
<canvas id="myChart"></canvas>
</div>
<script>
// 우선 컨텍스트를 가져옵니다.
var ctx = document.getElementById("myChart_<?php echo $list[$i]['wr_id']?>").getContext('2d');
해당부분의 canvas 아이디와 스크립트에서 가져오는 아이디가 중복되서 그렇습니다.
<canvas id="myChart_<?php echo $list[$i]['wr_id']?>"></canvas>
등의 형태로 중복이 되지 않게 변경하세요