Local Binding

This article shows how to bind Kendo UI Sparkline for PHP to a PHP array.


This PHP array can be populated from a database or declared inline (in the page).

Bind to PDO-Returned Arrays

PHP Data Objects (PDO) is an interface for accessing various databases in PHP.

Below are listed the steps for you to follow when binding the Kendo UI Sparkline for PHP to an array returned by PDO.


The following demo is using the sample SQLite database shipped with the Telerik UI for PHP demos (/wrappers/php/sample.db).

Step 1 Make sure you followed all the steps from the introductory article on Telerik UI for PHP—include the autoloader, JavaScript, and CSS files.

Step 2 Create a PDO connection.

    $db = new PDO('sqlite:../sample.db');

Step 3 Retrieve all records from the Weather table.

    $statement = $db->prepare('SELECT TMax FROM Weather LIMIT 10');
    $weather = $statement->fetchAll(PDO::FETCH_ASSOC);

Step 4 Create a data source and set its data and schema. Setting the schema is required to specify the model fields. Those fields are required for filtering and editing.

    // Create the schema model
    $model = new \Kendo\Data\DataSourceSchemaModel();

    // Create a field for the 'TMax' column of the 'Weather' table
    $tmaxField = new \Kendo\Data\DataSourceSchemaModelField('TMax');


    // Create the schema
    $schema = new \Kendo\Data\DataSourceSchema();

    // Set its model

    // Create the data source
    $dataSource = new \Kendo\Data\DataSource();

    // Specify the schema and data

Step 5 Create a Sparkline, configure its series.

    $sparkline = new \Kendo\Dataviz\UI\Sparkline('sparkline');

    $tmaxSeries = new \Kendo\Dataviz\UI\SparklineSeriesItem();


Step 6 Output the Sparkline by echoing the result of the render method.

    echo $sparkline->render();

See Also

In this article