I am trying to execute a SQL query within a JavaScript (.JS) file. My attempt to integrate PHP code didn’t work as I expected. The specific SQL query I want to run is: SELECT cost FROM items WHERE id=1
. My goal is to display the cost on a chart. Does anyone have insights on how I can execute this SQL query in the .JS file to retrieve the item’s cost from the database?
Currently, I am utilizing the following JavaScript code:
/* Chart.js Visualizations */
// Revenue chart setup
var chart1 = new Chart.Area({
target: 'sales-chart',
responsive: true,
dataset: [
{period: '2016 Q1', productA: 5000, productB: 4460},
{period: '2016 Q2', productA: 8432, productB: 5713}
],
labels: ['period', 'productA', 'productB'],
colors: ['#a0d0e0', '#3c8dbc'],
autoHide: 'on'
});
var chart2 = new Chart.Line({
target: 'trend-chart',
responsive: true,
dataset: [
{period: '2015 Q4', productA: 0},
{period: '2016 Q1', productA: 5000},
{period: '2016 Q2', productA: 8432}
],
labels: ['period', 'productA'],
colors: ['#efefef'],
lineThickness: 2,
autoHide: 'on',
textColor: "#fff",
stroke: 0.4,
pointSize: 4,
pointColors: ["#efefef"],
gridColor: "#efefef",
textFont: "Open Sans",
textSize: 10
});