I have a jakosc-powietrza.js file containing functions like this:
var combo1 = document.getElementById('S0_Data');
function test() {
var dzien = combo1.value.trim();
alert("Wybrano " + dzien);
};
function render_test() {
var test1 = <?php echo x; ?>;
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2",
animationEnabled: true,
title: {
text: "Pomiar parametrów powietrza",
fontSize: 25
},
axisX: {
title: "Czas",
titleFontSize: 15,
labelAngle: -90,
intervalType: "hour",
interval:55
},
axisY: {
title: "oC/%",
titleFontSize: 15
},
axisY2: {
title: "ppm/ppb",
titleFontSize: 15
},
data: [
{
type: "line",
color: "red",
name: "Temperatura",
showInLegend: true,
dataPoints: <?php echo json_encode($data_points, JSON_NUMERIC_CHECK); ?>
},
{
type: "line",
color: "green",
name: "Wilgotność",
showInLegend: true,
dataPoints: <?php echo json_encode($data_points2, JSON_NUMERIC_CHECK); ?>
},
{
type: "line",
color: "blue",
name: "eCO2",
axisYType: "secondary",
showInLegend: true,
dataPoints: <?php echo json_encode($data_points3, JSON_NUMERIC_CHECK); ?>
},
{
type: "line",
color: "yellow",
name: "TVOC",
axisYType: "secondary",
showInLegend: true,
dataPoints: <?php echo json_encode($data_points4, JSON_NUMERIC_CHECK); ?>
}
]
});
chart.render();
};
combo1.addEventListener('change', render_test, false);
I include it into test.php file like this:
<script type="text/javascript" src="js/jakosc-powietrza.js"></script>
When I open test.php file using browser I got the following error in web console:
SyntaxError: expected expression, got '<'
...and it points to this:
var test1 = <?php echo x; ?>;
Any pointers what I am doing wrong?