You must be logged in to post your query.
Home › Forums › Chart Support › A variable for dataPoints
Hello,
I downloaded canvasJS recently and I encountered a problem that I wasn’t able to solve.
In my code if I do :
`
window.onload = function () {
var tableauDataPoints = [
{ label: "apple", y: 10 },
{ label: "orange", y: 15 }
];
[...]
data: [
{
type: "column",
dataPoints: tableauDataPoints
}
]
[...]
The graphic will be displayed and I have no problem.
However I need to fill this table otherwise.
So I did :
window.onload = function () {
var tableauDataPoints = new Object(); /* I also tested with [] and new Array() */
for (i = 1; i < 3; i++) {
tableauDataPoints[i] = { label: "test", y: i };
alert(tableauDataPoints[i].label + tableauDataPoints[i].y);
}
[...]
data: [
{
type: "column",
dataPoints: tableauDataPoints
}
]
[...]
The alerts are correct, but I have no display, and I have no idea why, so I changed the variable type of “tableauDataPoints”, but no effect.
If you have any idea, it will be really helpful!
Thanks in advance,
Stupefiant,
DataPoints needs to be an array. Can you try var tableauDataPoints = [] instead?
If the above suggestion doesn’t work, please re-create the issue on JSFiddle, so that I can figure out the problem.
—
Sunil Urs
$.each(data, function (i, item) {
dps.push(“{label: “+item.ProfileName+”, y:”+ item.TotalCustomer+”},”);
alert(dps[0]);
});
How do i do this..?
is it possible for a datapoints to be like that..?
i cant render the Chart because I do not know the format.
You can build datapoints JSON as shown below.
$.each(data, function (i, item) {
dps.push({label: item.ProfileName, y: item.TotalCustomer});
});
Please take a look at this JSFiddle for an example.
—
Vishwas R
Team CanvasJS
Hi, i have the almost the same question.
The following code is working:
<script type="text/javascript">
window.onload = function () {
var data = [
{ Name: "Open System", Total: os },
{ Name: "Rationeel", Total: r },
{ Name: "Intern Proces", Total: ip },
{ Name: "Human Relations", Total: hr }
];
var dps=[];
$.each(data, function (i, item) {
dps.push({label: item.Name, y: item.Total });
//alert(dps[0]);
});
var chart = new CanvasJS.Chart("chartContainer",
{
data: [
{
type: "column",
dataPoints: dps
}
],
title:{
text: "De vier kwadranten"
},
axisY:{
stripLines:[
{
value:4
}
]
},
});
chart.render();
}
</script>
Only the variables for Total aren’t working.
The variables are in my code like this:
var os = "<?php echo $os; ?>";
var r = "<?php echo $r; ?>";
var ip = "<?php echo $ip; ?>";
var hr = "<?php echo $hr; ?>";
Can you solve my problem? I want the php-variables in the chart.
The php tot js variable lines are working, so the problem is in the code of the chart.
You must be logged in to reply to this topic.