summaryrefslogtreecommitdiffstats
path: root/docs/tutorial_example_28.php
blob: 2a2135c4ffff48eb3b6619b1cf3c131ea8add3ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

require_once 'tutorial_autoload.php';

$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEz();
$graph->title = 'Access statistics';

$graph->data['Access statistics'] = new ezcGraphArrayDataSet( array(
    'Mozilla' => 19113,
    'Explorer' => 10917,
    'Opera' => 1464,
    'Safari' => 652,
    'Konqueror' => 474,
) );

$graph->render( 400, 200, 'tutorial_example_28.svg' );

// Get element references from renderer
$elements = $graph->renderer->getElementReferences();

// Add links to charts
$dom = new DOMDocument();
$dom->load( 'tutorial_example_28.svg' );
$xpath = new DomXPath( $dom );

// Link chart elements
foreach( $elements['data']['Access statistics'] as $objectName => $ids )
{
    foreach ( $ids as $id )
    {
        echo "Link: $id\n";
        $element = $xpath->query( '//*[@id = \'' . $id . '\']' )->item( 0 );

        $element->setAttribute( 'style', $element->getAttribute( 'style' ) . ' cursor: pointer;' );
        $element->setAttribute( 'onclick', 'top.location = \'/detailedData.php?browser=' . $objectName . '\'' );
    }
}

// Link legend elements
foreach( $elements['legend'] as $objectName => $ids )
{
    foreach ( $ids as $id )
    {
        echo "Link: $id\n";
        $element = $xpath->query( '//*[@id = \'' . $id . '\']' )->item( 0 );

        $element->setAttribute( 'style', $element->getAttribute( 'style' ) . ' cursor: pointer;' );
        $element->setAttribute( 'onclick', 'top.location = \'/detailedData.php?browser=' . $objectName . '\'' );
    }
}

$dom->save( 'tutorial_example_28.svg' );

?>
OpenPOWER on IntegriCloud