<!-- 搜索表單 --> ... <div id="show-statistical"></div> <script src="/snsshop_admin/js/libs/highcharts/highcharts.js"></script> <script src="/snsshop_admin/js/libs/highcharts/exporting.js"></script> <script type="text/javascript" src="/snsshop_admin/js/libs/datePicker/WdatePicker.js"></script> < script> var chart = new Highcharts.Chart({ chart: { renderTo: 'show-statistical', type: 'line', // marginRight: 30, // marginBottom: 25 }, title: { text: '', x: -20 //center }, subtitle: { text: '', x: -20 }, xAxis: { categories: [], }, yAxis: { title: { text: '' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { valueSuffix: '' }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'middle', borderWidth: 0 }, series: [{ name: '會員新增統計', data: [] }, { name: '會員充值統計', data: [] }] }); $("#select-users").submit(function(event) { event.preventDefault(); $.post('/snsshop_admin/managers/statistical', $("#select-users").serialize(), function(data) { // 返回一個 JSON chart.xAxis[0].setCategories(data[0]); chart.series[0].setData(data[1]); chart.series[1].setData(data[2]); },'json'); return false; }); // 默認自動提交 $("#select-users").submit();
參考資料:
Highcharts set x-axis categoriesjavascript