douzoudang1511 2011-04-11 08:49
浏览 50
已采纳

从mysql图形化数据

I have a mysql result sorted on date and grouped by date and id.

SELECT
  DATE(`created_at`) AS `date`,
  COUNT(`id`) AS `count`,
  `account_id`
FROM `streamaccounts`
GROUP BY `date`, `account_id`
ORDER BY `date`;

And the result is this:

date, count, account_id
2011-03-23, 2, 1
2011-03-23, 1, 6
2011-04-25, 1, 1
2011-04-26, 5, 6

If you ask me, that's the right result set for using it to make a graph with highcharts. But I into the following problem.

I cannot figure out how to create the right result for highcharts. The result has to look something like this:

series: [{name: 'account1', data: [2, 1]}, {name: 'account2', data: [1, 5}]

It will all be programmed in PHP and echo'd out to print out valid javascript. What do I do? Will I need to loop through all dates first and check if in that date is a valid result? Or do I loop through all the accounts first and check for a valid date.

Any suggestions?

Thanks in advance!

  • 写回答

3条回答 默认 最新

  • douju1968 2011-04-15 13:29
    关注

    It has been way easier for me to get Highchart to do the data processing work from SQL queries by converting the data to one of the following formats:

    1. Convert an HTML table (this is helps meet accessibility standards) demo here: http://www.highcharts.com/studies/table-parser.htm
    2. Using AJAX, read in a CSV file - demo here: http://www.highcharts.com/studies/data-from-csv.htm

    Since your query is already doing a CSV file, just follow the example for #2.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程