First point: separate your presentation from your data/business logic.
Make two pages, one for you html/css/javascript, and one for your php/
sql/json.
If you think about it, having 6 languages in a single document is
undoubtedly overwhelming.
Using this technique you can then request your data through your biz/
data layer page independently of your presentation. This will give you
a returned text blob of json text that you can then check for
correctness. Get your php/sql/json all returning exactly what you want
to use in your presentation layer and then move on to your charting.
You'll have to use ajax to fetch your data, but this will be so much
easier as you build out your web site.
When you do this you should now have a json object with you multiple
set of data
{
"dataPayloadA" : [0:.0, 1:.1, 2:.2, 3:.3, 4:.4],
"dataPayloadB" : [0:1.1, 1:1.1, 2:1.2, 3:.13, 4:1.4]
}
This should resemble the text you get back from your data page query.
Then you just perform two plots using the json.dataPayloadA for one
and the json.dataPayloadB for the other.
You'll have two different place holders for the two different charts.
You can line them up with axis margin widths if you need them stacked
and perfectly tracking (top to bottom).
Much simpler now I'd say.
-DC