-1

The graph is not plotted if I select the select item .

I pass the selected select by ajax to a php file. The graphic plated only with a constant variable in the php file. I think this is due to the fact that the graphic plated once when the page is opened and is not updated.

app.js:

$(function() {
    $.ajax({
        url: 'chart_data.php',
        type: 'GET',
        success: function(data) {
            chartData = data;
            var chartProperties = {
                "xAxisName": "Type cell",
                "yAxisName": "Number of votes",
                "rotatevalues": "1",
                "theme": "zune"
            };

            apiChart = new FusionCharts({
                type: 'column2d',
                numbersuffix: " Transactions",
                renderAt: 'chart-container',
                width: '500',
                height: '350',
                dataFormat: 'json',
                dataSource: {
                    "chart": chartProperties,
                    "data": chartData
                }
            });
            apiChart.updateChart();
        },
    });
});

stat.php:

<div id="pie">
      <div id="chart-container">The diagram will be displayed here</div>  
</div>
<label for="exampleInputEmail1" class="form-label">Select a marker</label>

<?php
$db = mysqli_connect("", "", "","");
$marker = mysqli_query($db, "SELECT * FROM marker where id_fullimage='$id'");
echo '<select id="id_marker" name="id_marker" class="form-select"  aria-label="Default select example" required onchange="myFunction()">';

while($result = mysqli_fetch_array($marker)){
    echo "<option value=".$result['id_marker'].">".$result['id_marker']."</option>";
 } 

echo "</select>";
?>

<script>
function myFunction(){
  var id_marker = $('#id_marker').val();
  console.log(id_marker);

  $.ajax({
    type: 'POST',
    url: 'chart_data.php',
    dataFormat: 'json',
    data: {
     id_marker:id_marker
    },
    success: function () {
    },
    error: function () {
      alert("ошибка");
    }
  });
};
</script>
Yana
  • 1
  • 1
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 18 '22 at 13:05
  • Ok. I'm just learning – Yana May 18 '22 at 13:30
  • It looks like you are using some really bad tutorial. I highly encourage you to find something better. If you are only starting to learn PHP then you should learn PDO instead of mysqli. PDO is much easier and more suitable for beginners. Start here https://phpdelusions.net/pdo & https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection. Here are some good video tutorials https://youtu.be/2eebptXfEvw & https://www.youtube.com/watch?v=sVbEyFZKgqk&list=PLr3d3QYzkw2xabQRUpcZ_IBk9W50M9pe- – Dharman May 18 '22 at 13:34
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community May 18 '22 at 16:30

0 Answers0