score:3
I guess you are doing it in an .js file. I guess your webserver ist not interpreting php code. Instead it is serving it as static javascript code.
Do it in a <script></script>
in an .php file.
If you dont want to pass variable by variable to javascript:
Pass it as json
.
An example can be found here:
score:0
This was helpfull!
I just changed my HTML doc to PHP, and then IT WORKS!
I am a rookie in code-develeper stuff, but my tip por MySQL cx is this.
Query:
<?php
session_start();
include_once "con.php"; #my conex in another doc
$query= "SELECT * FROM data ORDER BY id";
$result= mysql_query($query);
#For a simple first look, or rookies like me... I show the query result w/ an echo.
while ($row= mysql_fetch_assoc($result)){
echo $row['id'] . ' | ' . $row['mes'] . ' | ' . $row['valor1'] . ' % | ' . $row['valor2'] . ' % | ' . $row['valor3']. ' %' ."\n";
#This is what we need: I put data from my query in $setx, and then I use user3271851's code... it works!
$set1= $row['valor1'];
$set2= $row['valor2'];
$set3= $row['valor3'];
}
?>
For the Chart, just like the post:
var pieData = [
{
value: <?php echo $set1; ?>,
color:"#F38630"
},
{
value : <?php echo $set2; ?>,
color : "#E0E4CC"
},
{
value : <?php echo $set3; ?>,
color : "#69D2E7"
}
];
var myPie = new Chart(document.getElementById("canvas").getContext("2d")).Pie(pieData);
P.S.: Sorry, my english is not good at all. :)
score:1
Make the array of colors and pass your $row inside a foreach loop just like this.
foreach($row as $key=>$value)
{
$data[$key]['value']=(int)$value['id'];
$data[$key]['color'] = $color[$key];
}
And after that convert data into json like this
var Data = <?php echo json_encode($dataArr['data']); ?>;
Source: stackoverflow.com
Related Query
- Configure Pie Chart Colors Using Chart.js and PHP
- Trying to load a chart with chart.js, through ajax and php
- Grouped Bar Chart from mySQL database using ChartJS and PHP
- Dynamic line chart with chart.js and PHP
- create Chart using Chartjs and PHP
- Chart js PHP and JSON wont diplsay
- Dynamically create chart with Chart.js and PHP
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Chart.js, PHP and radar chart labels
- In Chart.js set chart title, name of x axis and y axis?
- Chart.js - Increase spacing between legend and chart
- Chart.js: bar chart first bar and last bar not displaying in full
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- chartjs datalabels change font and color of text displaying inside pie chart
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Chart.js Mixed Bar and Line chart with different scales
- Chart.js bar chart : Grid color and hide label
- Problem for display a chart with Chart.js and Angular
- How to use PrimeNg Chart of Width and Height?
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Chart.js Timeseries chart - formatting and missing data values
- chartjs - top and bottom padding of a chart area
- Draw a horizontal and vertical line on mouse hover in chart js
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Category scale on Y-axis and time on x-axis in bubble chart in Chartjs
- Can Chart.js combines Line Chart and Bar Chart in one canvas
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Chart.js - Getting data from database using mysql and php
- Creating a grouped and stacked chart in Chart.js
More Query from same tag
- Chart.js legend - split into two and display separately?
- How to correctly transform data for a stack chart chartJS (data transformation)?
- Adding hours and minutes to a date object for time axis
- Chart.js letter spacing very awkward
- Pie chart not working using angular and ng2-charts
- chart.js - line chart - can I visualize positive/negative change somehow?
- Formatting Data With Charts.JS
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- ng-chart.js - First data set always has color gray
- show text in both y axis in dual axis chart js
- Can we have both ajax and jquery scripts in one function?
- How to set label in dataPoints chart on javascript?
- How to plot data coming async in a chartjs chart
- Charts on Admin-on-rest
- Chartjs doughnut segment pattern
- Creating multiple charts and selecting them later
- ChartJS line chart or bar graph from a Java program
- ChartJS Legend Not Lining Up
- How to fill the gaps in an array of Dates with fixed length
- Chart JS - Title missing when clearing canvas if no data is available
- Chart.JS Chart top left corner is blocked by some visual nodejs
- Set labels from array
- Drill Down Chart find Index returns -1
- How do I get a chart.js chart to display data in a Node/React web application?
- Modifying values in a radar chart.js based on user input
- How to disable a tooltip for a specific dataset in ChartJS
- How to add padding to the vertical scale (X-axis) in Chart.js?
- Chart.js not working on Angular 1.5?
- How to append text or symbol to tooltip of chart.js
- Chart.js creating a line graph using dates