下面的代码生成一个包含每日每周或每月数据的 morris 图表。这很好,但是,我需要传递下拉“汽车”中的变量,并在 php 中创建一个 var 来运行 sql 选择。任何人都可以帮助我在 php 中生成这个 var 吗?非常感谢!!!熟 <div id="line-chart" style="height: 300px;"><h3 style="text-align: center;">Waiting for you to choose the data you want to display</h3></div><hr/><button data-type="day">Day</button> | <button data-type="week">Week</button> | <button data-type="month">Month</button><select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option></select></body> </html><script> jQuery(function($) { $('button').on('click', function(e) { $('#line-chart').empty(); var type = $(this).data('type') , month = [ { y: '2012-06', a: 100, b: 90 }, { y: '2012-07', a: 75, b: 65 }, { y: '2012-08', a: 50, b: 40 }, { y: '2012-09', a: 75, b: 65 }, { y: '2012-10', a: 50, b: 40 }, { y: '2012-11', a: 75, b: 65 }, { y: '2012-12', a: 100, b: 90 } ] , week = [ { y: '2012 W1', a: 10, b: 20 }, { y: '2012 W2', a: 50, b: 10 }, { y: '2012 W3', a: 40, b: 80 }, { y: '2012 W4', a: 90, b: 25 }, { y: '2012 W5', a: 10, b: 20 }, { y: '2012 W6', a: 35, b: 60 }, { y: '2012 W7', a: 8, b: 40 } ] , day = [ { y: '2012-12-25', a: 20, b: 50 }, { y: '2012-12-26', a: 30, b: 30 }, { y: '2012-12-27', a: 100, b: 10 }, { y: '2012-12-28', a: 10, b: 15 }, { y: '2012-12-29', a: 80, b: 60 }, { y: '2012-12-30', a: 20, b: 65 }, { y: '2012-12-31', a: 5, b: 95 } ] , data = { month: month, week: week, day: day } }) ; }); }); </script>
1 回答

凤凰求蛊
TA贡献1825条经验 获得超4个赞
您需要在 select 元素上使用 onChange 事件,然后在里面,您可以调用用 PHP 编写的服务器端 API。然后可以使用从服务器返回的数据来使用函数 setData() 更新图表。
- 1 回答
- 0 关注
- 77 浏览
添加回答
举报
0/150
提交
取消