The problem with this method (and current query) is that it isn't always guaranteed the total integers will be in the order of your labels - so whilst the total for 'Cars' maybe 10, you could actually end up with the total for buses etc.
If the
type_id is an incremental integer then you could stick an ORDER on the
type_id column in the query, at least then you could match up the labels to the dataset.
However, personally i'd do this from a slightly different angle - firstly, use PHP to generate a multidimensional array, then encode and output (with the correct headers) JSON data, something like -
Code:
{
"Cars": {
"Ibiza": 10,
"Escort": 20,
"Focus": 15
},
"Bus": {
"Yellow": 3,
"Red": 5
},
"Lorry": {
"Big": 10,
"Small": 5
}
}
Then use JS (or a JS library) to grab the JSON data (via Ajax/XHR), iterate through it and create instances of the charts accordingly (or if ChartJS supports external datasets then try and use the built in functions).
Doing it this way, you not only grab the label names for both types and models but also the totals (obviously totals for types would be a sum of the model totals).
A bit more work but it gives you a little more flexibility if you wanted to add additional types or models etc.