Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

I am making a line graph using a jQuery plug in and the script is as follows

<script>

var lineChartData = {
    labels : ["1","2","3","4","5","6","7","8","9","10","11","12"],
    datasets : [
        {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,1)",
            pointColor : "rgba(220,220,220,1)",
            pointStrokeolor : "#fff",
            data : [5,6,19,34,59,93,128,158,206,266,329,398,418]
        },

        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [0,0,0,3,15,46,68,109,169,228,319,364,386]
        }
        ]   

    }

var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);

I want to insert a variable into the data part of the var, for example

data : [$q1,$q2,$q3, etc, etc]

I have no idea about javascript so I don't know where to begin. How would I do this?

I have the variables in a separate file and have included it this file.

share|improve this question

marked as duplicate by Pitchinnate, Shomz, mamdouh alramadan, e-sushi, jaypal Apr 3 at 22:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Just echo them. I'm sure if you did a search you could find many questions that are the same. –  Pitchinnate Apr 3 at 20:57
    
I'm assuming you down voted? As I said I know nothing about javascript and it was incredibly confusing - hence the reason I asked the question. I tried a few methods my self but none worked –  Aasim Azam Apr 3 at 20:59
add comment

1 Answer

up vote 6 down vote accepted

When rendering the page you could drop in your PHP like:

data : [<?php echo "$q1,$q2,$q3, etc, etc";?>]
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.