如何将输入乘以php中所选选项的值并显示在jQuery图表中?

I need two operations with the same form using php without reload the page and display the results in the chart. I'm using canvasjs for the chart. The first, is to multiply the value of input by the value of the selected option. And the second is the same but adding a 4%.

<?php
  if(isset($_POST['calculate'])) {
   $a= $_POST['a']; 
   $b= $_POST['b'];
   $result1= $a * $b;
   $result2= $a * $b + '4%';
?>
<form method="post">
  <input type="text" name="a" id="a">
  <select name="b" id="b">
    <option value="" disable selected>Select an amount</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
  </select>
  <button type="submit" id="calculate" value="Calculate">
</form>
<script type="text/javascript">
    window.onload = function () {
        var chart = new CanvasJS.Chart("chartContainer", {
            title: {
                text: "Results"
            },
            data: [{
                type: "column",
                dataPoints: [
                    { y: <?php echo $result1; ?>, label: "Result 1" },
                    { y: <?php echo $result2; ?>, label: "Result 2" },
                ]
            }]
        });
        chart.render();
    }
</script>

Other solutions without altering the form and the chart are welcome.

Why you need to multiply the data on php simply you can do it on jquery onchange event and calculate the data var x = (100 + 50) * a; in your js page onwards. it is much simple and better for select box data change.

Using javaScript event listener you can achieve your requirement. I hope adding following lines within window load should work fine.

var input = <?php echo $a?>;

var selector = document.getElementById('b');
document.getElementById("calculate").addEventListener("click",  function(){
    var multiplicationFactor = selector.options[selector.selectedIndex].value;
    chart.options.data[0].dataPoints[0].y = input * multiplicationFactor;
    chart.options.data[0].dataPoints[1].y = input * multiplicationFactor * 1.04;
    chart.render();
});