Edit this page

Sparkline PHP Class Overview

The Kendo UI Sparkline for PHP is a server-side wrapper for the Kendo UI Sparkline widget.

Getting Started

The Basics

There are two ways to bind a Kendo UI Sparkline for PHP:

  • Locally—Local binding binds the Sparkline to a PHP array.
  • Remotely—During remote binding the Sparkline makes AJAX requests and is bound to the JSON result.

Configuration

Below are listed the steps for you to follow when configuring the Kendo UI Sparkline for local binding.

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 an array to which the Sparkline will be bound.

Example
    <?php
    $data = array(1, 3, 5, 4, 2);
    ?>

Step 3 Create a Sparkline, configure its data.

Example
    <?php
    $sparkline = new \Kendo\Dataviz\UI\Sparkline('sparkline');
    $sparkline->data($data);
    ?>

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

Example
    <?php
    echo $sparkline->render();
    ?>

Event Handling

You can subscribe to all Sparkline events.

Specify Function Names

The example below demonstrates how to subscribe for events by specifying a JavaScript function name.

Example
    <?php
    $sparkline = new \Kendo\Dataviz\UI\Sparkline('sparkline');

    // The 'sparkline_dataBound' JavaScript function will handle the 'dataBound' event of the sparkline
    $sparkline->dataBound('sparkline_dataBound');

    echo $sparkline->render();
    ?>
    <script>
    function sparkline_dataBound() {
        // Handle the dataBound event
    }
    </script>

Provide Inline Code

The example below demonstrates how to provide inline JavaScript code.

Example
    <?php
    $sparkline = new \Kendo\Dataviz\UI\Sparkline('sparkline');

    // Provide inline JavaScript code that will handle the 'dataBound' event of the sparkline
    $sparkline->dataBound('function() { /* Handle the dataBound event */ }');

    echo $sparkline->render();
    ?>

Reference

Client-Side Instances

You can reference the client-side Kendo UI Sparkline instance via jQuery.data(). Once a reference is established, use the Sparkline API to control its behavior.

Example
    <?php
    $sparkline = new \Kendo\Dataviz\UI\Sparkline('sparkline');
    echo $sparkline->render();
    ?>
    <script>
    $(function() {
        // The constructor parameter is used as the 'id' HTML attribute of the sparkline
        var sparkline = $("#sparkline").data("kendoSparkline")
    });
    </script>

See Also

Other articles on Telerik UI for PHP and on the Sparkline:

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy