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 824 to 849

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 27th April 2024 12:05 Europe/London time based on the source file dated 10th April 2024 18:30 Europe/London time.