You need to sign in to do that
Don't have an account?
Thakkar Parth
SCRIPT1007: Expected ']' error
I'm getting an error while displaying Highcharts . The error is : SCRIPT1007: Expected ']' at line 47,character 4. Pressing my head since hours and trying to solve but no luck yet :( .Really appreciate the help.Thanks in advance. Marc
==== Class ===
=== Page ===
==== Class ===
public class HighChartsController3 { public String[] total; public String[] gettotal() { String q = 'SELECT count(Id),Name Total FROM Account group by Name'; AggregateResult[] agr =Database.query(q); String[] strarray = new String[agr.size()]; for (AggregateResult ar : agr) { strarray.add(String.valueof(ar.get('Total'))); } return strarray ; } public String[] position; public String[] getposition() { String q = 'SELECT count(Id),Name FROM Opportunity group by Name'; AggregateResult[] agr =Database.query(q); String[] strarray = new String[agr.size()]; for (AggregateResult ar : agr) { strarray.add(string.valueOf(ar.get('Name'))); } return strarray ; } }
=== Page ===
<apex:page controller="HighChartsController3"> <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" /> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> <Script> $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'Total # of Apllications vs # of Open Jobs' }, xAxis: { categories: {!position} // categories: ['abc','parth','hello'] }, yAxis: { allowDecimals: false, min: 0, title: { text: 'Number' } }, tooltip: { formatter: function () { return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal; } }, plotOptions: { column: { stacking: 'normal' } }, series: [{ name: 'New', data: [5, 3, 4, 7, 2], stack: 'Application' }, { name: 'Schedule Interviews', data: [3, 4, 4, 2, 5], stack: 'Application' }, { name: 'Hired', data: [3, 4, 4, 2, 5], stack: 'Application' },{ name: 'Rejected', data: [3, 4, 4, 2, 5], stack: 'Application' }, { name : 'Total Applications', data : {!total} //data : [100,200,300], stack : 'Total' }] }); }); </script> </apex:page>
There are couple of changes you need to do
On visualforce page - Place a comma after {!total}
The main change is in controller class. When you are returning list of String its coming as it on vf page without single quotes that will represent it as string on script. We are adding it additionally.
Let us know if it helps.
Cheers,
Prafull
i.e.
strarray.add('\"' + string.valueOf(ar.get('Name')) + '\"');