如何使用两个不同的mysql表值到x轴和y轴的数据创建php折线图?

Thank you for reading this. I may not have done enough research, however I have been looking around regarding my question but there are not sufficient resource.

Here I have two MySQL tables metrics and metric_stats.

  CREATE TABLE `metrics` (
  `metric_id` int(10) NOT NULL,
  `metric_name` varchar(40),
  `min_ideal` int(10),
  `max_ideal` int(10),
  `min_range` int(10),
  `max_range` int(10),
  PRIMARY KEY (`metric_id`)
) 

CREATE TABLE `metric_stats` (
  `stat_id` int(10) NOT NULL,
  `stat_value` int(10),
  `added` DATE',
  `metric_id` int(10) NOT NULL,
  PRIMARY KEY (`stat_id`)
) 

Whenever I add new metric type into metrics table there should a new graph be generated straight away, even though it does not have any metric_stats value. Then when I add new values to metric_stats table, should graphs be updated accordingly.

X-axis should show min_range, min_ideal, max_ideal, max_range. Y-axis should list added date values.

here is the scratch

I attached the desired output.

Any thoughts on this? or any help? or any suggestion? I would appreciate your help guys

I think I might have to use jpgraph or amcharts.

Make your JOIN query, iterate result and make it key value array. JSON encode it and pass it to your library.