Accepted answer

If your goal is to keep this dynamic, by being able to build multiple charts with multiple renderTo's but using the same options, you can do it like this:


function createChart(questiontitle, answers){
    chart = new Highcharts.Chart(options); 


function createChart(questiontitle, answers){
    chart = $('#container').highcharts(options); 

or, if not using jQuery,

function createChart(questiontitle, answers){
    options.chart.renderTo = 'container';
    chart = new Highcharts.Chart(options); 


You may be facing the same problem that i was. Try to put your highchart script right after your div's declaration just like in the example bellow so it can recognize your div's id:

    <title>HighCharts :D</title>
    <script src=""></script>
    <script type="text/javascript" src=""></script>
<div id="container" style="width: 600px; height: 400px; margin: 0 auto">
<script type="text/javascript">
    var myChart = Highcharts.chart('container', {
        chart: {
            type: 'bar'
        title: {
            text: 'Fruit Consumption'
        xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
        yAxis: {
            title: {
                text: 'Fruit eaten'
        series: [{
            name: 'Jane',
            data: [1, 0, 4]
        }, {
            name: 'John',
            data: [5, 7, 3]



Something like this: chart.renderTo(container); doesn't exists in Highcharts.

To set renderTo use options:

var options = {
    chart: {
        type: 'bar',
        renderTo: 'container'


In case someone stumbles on this while Googling, when you specific the element in renderTo, you shouldn't include the # if that element is an ID.

If you have this element <div id="graph-container"></div>

This fails: renderTo: '#graph-container'

This works: renderTo: 'graph-container'

Reference to the Highcharts docs

Related Query

More Query from same tag