Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

render_bar_graph()

Description

Output the Javascript to build a bar chart in the canvas denoted by $id
$data must be in the following format
$data = array(
"point_a x value" => "point_a y value",
"point_b x value" => "point_b y value",

Parameters

ColumnTypeDefaultDescription
$id string identifier for the canvas to render the chart in
$data array data to be rendered in the chart

Return

void

Location

include/reporting_functions.php lines 827 to 852

Definition

 
function render_bar_graph(string $id, array $data)
    {
    
$values "";
    foreach (
$data as $t => $c)
        {
        
$values .= "{x: $t, y: $c },\n";
        }
    
?>
    <script type="text/javascript">
        new Chart(
            document.getElementById(' echo escape($id?>'),
            {
            type: 'line',
            data: {
                datasets: [
                    {
                        data: [ echo escape($values?>]
                    }
                ]
            },
            options: chartstyling echo escape($id)?>,
        }
        );
    </script>
    
    
}

This article was last updated 21st May 2024 10:35 Europe/London time based on the source file dated 8th May 2024 18:45 Europe/London time.