View source
<?php
function flot_example_menu() {
$items['flot_example'] = array(
'title' => t('Flot example'),
'page callback' => 'flot_example_page',
'access callback' => TRUE,
);
if (module_exists('flot_views')) {
$items['flot_views_example'] = array(
'title' => t('Flot views example'),
'page callback' => 'flot_views_example_page',
'access callback' => TRUE,
);
}
return $items;
}
function flot_example_page() {
$content = '<h3>' . t('Lines') . '</h3>';
$d1 = new flotData(array(
array(
0,
1,
),
array(
4,
8,
),
array(
8,
5,
),
));
$d1->label = t('Example data 1');
$d2 = new flotData(array(
array(
0,
8,
),
array(
3,
5,
),
array(
8,
0.5,
),
));
$d2->label = t('Example data 2');
$d1->lines = new flotLine(array(
'lineWidth' => 5,
));
$d1->points = new flotPoint(array(
'radius' => 5,
));
$variables = array(
'data' => array(
$d1,
$d2,
),
'element' => array(
'id' => 'flot-example-normal',
'class' => 'flot-example',
'style' => "width:600px;height:400px",
),
'legend' => TRUE,
'zoom' => TRUE,
);
$content .= theme('flot_graph', $variables);
$content .= '<h3>' . t('Points') . '</h3>';
$d1 = new flotData(array(
array(
0,
1,
),
array(
4,
8,
),
array(
8,
5,
),
));
$d1->label = t('Example data 1');
$d1->points = new flotPoint(array(
'fillColor' => '#EDC240',
));
$d2 = new flotData(array(
array(
0,
8,
),
array(
3,
5,
),
array(
8,
0.5,
),
));
$d2->label = t('Example data 2');
$d2->points = new flotPoint();
$variables = array(
'data' => array(
$d1,
$d2,
),
'element' => array(
'id' => 'flot-example-normal',
'class' => 'flot-example',
'style' => "width:600px;height:400px",
),
'legend' => TRUE,
'zoom' => TRUE,
);
$content .= theme('flot_graph', $variables);
$content .= '<h3>' . t('Bars') . '</h3>';
$d1 = new flotData(array(
array(
0,
1,
),
array(
4,
8,
),
array(
8,
5,
),
));
$d1->label = t('Example data 1');
$d1->bars = new flotBar(array(
'lineWidth' => 1,
'barWidth' => 1,
));
$d2 = new flotData(array(
array(
0,
8,
),
array(
3,
5,
),
array(
8,
0.5,
),
));
$d2->label = t('Example data 2');
$d2->bars = new flotBar();
$variables = array(
'data' => array(
$d1,
$d2,
),
'element' => array(
'id' => 'flot-example-normal',
'class' => 'flot-example',
'style' => "width:600px;height:400px",
),
'legend' => TRUE,
'zoom' => TRUE,
);
$content .= theme('flot_graph', $variables);
$content .= '<h3>' . t('Pie') . '</h3>';
$d1 = new flotData(30);
$d1->label = t('Example data 1 (30%)');
$d1->pie = new flotPie();
$d2 = new flotData(70);
$d2->label = t('Example data 2 (70%)');
$d2->pie = new flotPie();
$variables = array(
'data' => array(
$d1,
$d2,
),
'element' => array(
'id' => 'flot-example-normal',
'class' => 'flot-example',
'style' => "width:600px;height:400px",
),
'legend' => FALSE,
'options' => array(
'pie' => TRUE,
),
);
$content .= theme('flot_graph', $variables);
$content .= '<h3>' . t('Combination') . '</h3>';
$d1 = new flotData(array(
array(
0,
1,
),
array(
4,
8,
),
array(
8,
5,
),
));
$d1->label = t('Example data 1');
$d1->lines = new flotLine();
$d1->points = new flotPoint();
$d1->bars = new flotBar();
$d2 = new flotData(array(
array(
0,
8,
),
array(
3,
5,
),
array(
8,
0.5,
),
));
$d2->label = t('Example data 2');
$d2->lines = new flotLine();
$d2->points = new flotPoint();
$d2->bars = new flotBar();
$variables = array(
'data' => array(
$d1,
$d2,
),
'element' => array(
'id' => 'flot-example-normal',
'class' => 'flot-example',
'style' => "width:600px;height:400px",
),
'legend' => TRUE,
'zoom' => TRUE,
);
$content .= theme('flot_graph', $variables);
return $content;
}
function flot_views_example_page() {
$output = "<p> You can see the raw view " . l('here', 'flot-example-view-raw') . '</p>';
return views_embed_view('flot_example_view', 'page') . $output;
}
function flot_example_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'flot_example') . '/views',
);
}