简体   繁体   English

用户单击提交时如何在图表中显示计算结果?

[英]How can I display calculated results in a graph when user clicks submit?

I'm using http://canvasjs.com/ to create a bar graph. 我正在使用http://canvasjs.com/创建条形图。 So far, when the user clicks 'submit' the entered numbers are displayed on a graph http://jsfiddle.net/jx9sJ/5/ . 到目前为止,当用户单击“提交”时,输入的数字将显示在图形http://jsfiddle.net/jx9sJ/5/上

Now, I'm trying to change it. 现在,我正在尝试更改它。 So the entered numbers are sent to ajax, calculations done, & then encoded using json_encode($total); 因此,将输入的数字发送到ajax,完成计算,然后使用json_encode($total);进行编码json_encode($total); I'm struggling to create the graph from the values, which are in json_encode . 我正在努力从json_encode的值创建图形。 How can this be done? 如何才能做到这一点?

Code so far 到目前为止的代码

$fortot2 = 5;
$fortot3 = 2;

if (is_numeric($numwelds) && is_numeric($numconwelds))
{
    $total['tot1'] = $numwelds + $numconwelds + $fortot3  ;
    $total['tot2'] = $numwelds + $numconwelds + $fortot2 ;
    $total['tot3'] = $numwelds + $numconwelds; 
    $response = json_encode($total);
    header("Content-Type: application/json");  
    echo $response;
    exit;
} 

Using print_r json_encode($total) is structured as 使用print_r json_encode($ total)的结构如下

  Array ( [tot1] => 3 [tot2] => 5 [tot3] => 1 ) 

First of all, 首先,

Array ( [tot1] => 3 [tot2] => 5 [tot3] => 1 ) 

is not json_encode d and rather looks like var_dump( $total ) . 不是json_encode d,而是看起来像var_dump( $total )

Then you have to populate the data object that is used on line 15 of your JSFiddle with the values from JSON, which requires some basic knowledge of AJAX. 然后,您必须使用JSON中的值填充JSFiddle的第15行上使用的data对象,这需要一些AJAX的基本知识。 I suggest that you first familiarize yourself with that. 我建议您首先熟悉一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM