user828647
user828647

Reputation: 515

Creating graph on webpage using Highcharts

I need to create a bargraph on my webpage using Highcharts. I am using the following code but nothing is displayed. I am new to scripting webpages so I am not sure what is wrong.

<div id="container1" style="width:100%; height:400px;"></div>

function create_graph(graph) {
    chart = new Highcharts.Chart ({
        chart: {
             height: 600,
             width: 1200,
             renderTo: container1,
             type: 'column'
             //reflow: false
        },
        title: {
            text: graph["graphTitle"]
        },
        xAxis: {
            categories: graph["xAxisLabels"]
        },
        yAxis: {
            min: 0,
            title: {
                text: graph["yaxisTitle"]
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y}</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: generateLineData(graph)
    });
}

graph = {"graphTitle": "Title" ,"xAxisLabels" : xAxisLabels, "xAxisTitle" : "Properties", "yAxisTitle" : "Average percentile", "yAxisValues" : array1}

Upvotes: 1

Views: 95

Answers (1)

lpg
lpg

Reputation: 4937

You must have the javascript vars xAxisLabels , array1 initialized before creating object graph. Then, of course, following the logic of your code, you should have a call to create_graph(graph);. Finally, your generateLineData() function should look like the following:

function generateLineData(g) {
    return [{ data: g["yAxisValues"] }];
}

if all these premises are fulfilled, then your graph should be displayed. You can verify it at this jsfiddle demo: http://jsfiddle.net/tgnu5941/2/

Upvotes: 1

Related Questions