아래 코드를 사용하여 예상 재무 잔액에 대한 꺾은 선형 차트를 생성하고 있습니다. 데이터는 MySQL 데이터베이스의 정보로 생성됩니다. 내가 뭘하고 싶은지는 페이지에 입력 필드가있는 양식을 사용하여 페이지가로드되면 사용자가 시작 잔액을 동적으로 설정할 수 있도록하여 차트가 올바른 시작 잔액으로 다시 그려지지만 이 작업을 수행하는 방법을 알아낼 수 없습니다.구글 라인 차트의 시작 값 설정 차트를 동적으로 다시 그리기
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'string'),
array('label' => 'Amount', 'type' => 'number')
);
[code to generate data goes here - i.e. calculating a balance for each date in the chart]
$balance = $balance - $monthly - $weekly + $session_total;
$temp = array();
$temp[] = array('v' => (string) $date_display);
$temp[] = array('v' => (string) $balance);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
//echo $jsonTable;
?>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var formatter = new google.visualization.NumberFormat({fractionDigits:2,prefix:'\u00A3'});
formatter.format(data, 1);
var options = {
pointSize: 5,
legend: 'none',
hAxis: { showTextEvery:31 },
series: {0:{color:'2E838F',lineWidth:2}},
chartArea: {left:50,width:"95%",height:"80%"},
backgroundColor: '#F7FBFC',
height: 400
};
// Instantiate and draw our chart, passing in some options.
//do not forget to check ur div ID
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div"></div>
사용자가 원하는 것은 데이터 세트의 시작 부분에 새로운 값 하나를 삽입 할 수 있다는 것입니다. 선을 다시 그려라. 그들이 제공 한 가치는 그 이후에 영향을 미치면 안된다. – cchana
@cchana 메시지를 보내 주셔서 감사합니다. 사용자가 시작 잔액을 입력하면 그래프의 나머지 점이 MySQL 데이터베이스의 값을 사용하여 계산됩니다. 따라서 밸런스가 한 항목에서 다음 항목으로 이동함에 따라 사용자가 입력하는 값은 물론 전체 차트에 영향을 미칩니다. 그러나 기본적으로 사용자가 입력하는 값은 그래프의 첫 번째 항목에 대한 변수 $ balance를 설정해야합니다. 이게 더 명확 해지기를 바란다. – Nick