I took a row from a database with php and mysql and put it in a the array $dataPoints6. Then i transfered it with json-encode in an js array. In Generel I want to use this array for data part of a line graph. The problem (checked with console.log) is, that there is always an y in every array part. See here ( :{y: "39"})
How can I delete this y? Without this y I can use an array for the x or y axis in a line graph. Here is my Code. Thx for your help.
<?php
$dataPoints6 = array();
try{
// Creating a new connection.
// Replace your-hostname, your-db, your-username, your-password according to your database
$link = new \PDO( 'mysql:host=localhost;dbname=alurhbuj3;charset=utf8mb4', //'mysql:host=localhost;dbname=canvasjs_db;charset=utf8mb4',
'cu7iymbi1b', //'root',
'Thomas100388', //'',
array(
\PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => false
)
);
$handle6 = $link->prepare("select y from Lt_data where nr=1");
$handle6->execute();
$result6 = $handle6->fetchAll(\PDO::FETCH_OBJ);
foreach($result6 as $row6){
array_push($dataPoints6, array($row6));
}
$link = null;
}
catch(\PDOException $ex){
}
?>
<script>
var js_array = <?php echo json_encode($dataPoints6); ?>;
var a =[2,4,6,8,10];
console.log(js_array);
var trace1 = {
x: a,
y: [1,2,3,4,5],
type: 'scatter'
};
var trace2 = {
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: 'scatter'
};
var data = [trace1, trace2];
var layout1 = {
yaxis: {rangemode: 'tozero',
showline: true,
zeroline: true}
};
var layout2 = {
yaxis: {rangemode: 'tozero',
zeroline: true}
};
Plotly.newPlot('div1', data, layout1);
Plotly.newPlot('div2', data, layout2);
</script>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</div>