easypiechart ajax,javascript - creating highchart with ajax json data - Stack Overflow

I'm trying to create a simple chart in a page using mysql data retrieved using a mysql script

I don't understand how to integrate the ajax call with the data required for the chart. I don;t know enough about the various charting plugins to make my life easy and am currently trialing highchart.

My php script returns the following json:

[{"name":"golfers"},{"data":[5.7879,6.6286,6.1724,5.3125,7.1481,6.1333,4.5769]}]

My chart script is:

$(function () {

visitorData(function(data) {

console.info(data);

$('#chart1').highcharts({

chart: {

type: 'column'

},

title: {

text: 'Average Visitors'

},

xAxis: {

categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

},

yAxis: {

title: {

text: 'Number of visitors'

}

},

series: data,

});

});

});

my function to make the ajax call:

$.ajax({

url: '/visitdata',

type: 'GET',

async: true,

dataType: "json",

success: function (data) {

console.warn(data);

return data;

}

});

But at the moment nothing is being displayed.

I'm not sure how to effectively make the ajax call and integrate it into the chart function. I decided on a callback based on earlier attempts and posts to ensure data is returned before creating the chart - is this bit correct?

I'm not 100% sure the json data is structured correctly

I'm not sure i;ve applied the data variable to the series correctly

Basically - need a tutorial on this so I can get it working and experiment

All help appreciated

Thanks

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值