# Creating Charts from Processed SQL Data

A chart is useful only when it makes a comparison or pattern easier to understand. JavaScript is a supporting technology; the assessed reasoning lies in the data choice, processing and justified output.

## Prepare data in PHP

~~~php
$labels = array_column($rows, "team_name");
$values = array_map("intval", array_column($rows, "points"));
~~~

Pass encoded data safely:

~~~html
<script>
const labels = <?= json_encode($labels) ?>;
const values = <?= json_encode($values) ?>;
</script>
~~~

A chart library can use these arrays. Provide a visible title, axis labels, sufficient contrast and a text/table alternative.

## Choose the chart

- bar chart: compare teams or categories
- line chart: change over ordered time
- avoid pie charts when many categories or close values impede comparison

Do not create a chart from raw unprocessed data when a grouped or calculated result is what users need.

## Check

- [ ] Chart answers a stated question.
- [ ] SQL/PHP processing is explainable.
- [ ] Labels and units are present.
- [ ] Equivalent values are available without relying only on colour or graphics.
- [ ] Empty and extreme datasets are tested.