示例#1
0
function stacked_bar_chart($host_instance_list)
{
    $title = new title('所有instance实际内存使用');
    $title->set_style("{color: #567300; font-size: 16px; font-weight:bold;}");
    $bar_stack = new bar_stack();
    $bar_stack->set_colours(array('#C4D318', '#7D7B6A'));
    $max = 64;
    foreach ($host_instance_list as $i => $instance) {
        $jvmmem = isset($instance['jvmmem']) ? explode('/', $instance['jvmmem']) : array();
        if ($jvmmem) {
            foreach ($jvmmem as &$j) {
                $j = intval($j);
            }
            $max = $max < $jvmmem[1] ? $jvmmem[1] : $max;
            $jvmmem[1] = $jvmmem[1] - $jvmmem[0];
        }
        $bar_stack->append_stack($jvmmem);
        $lables[] = $instance['port_num'];
        $services[$i] = $instance['service_name'];
    }
    $bar_stack->set_keys(array(new bar_stack_key('#C4D318', 'used', 13), new bar_stack_key('#7D7B6A', 'total', 13)));
    $bar_stack->set_on_click('(function(x){var services=' . json_encode($services) . ';alert(services[x]);})');
    //js
    $bar_stack->set_tooltip('#val#M,共#total#M');
    $y = new y_axis();
    $y->set_range(0, $max + 32, 256);
    $x = new x_axis();
    $x->set_labels_from_array($lables);
    $tooltip = new tooltip();
    $tooltip->set_hover();
    $chart = new open_flash_chart();
    $chart->set_title($title);
    $chart->add_element($bar_stack);
    $chart->set_x_axis($x);
    $chart->add_y_axis($y);
    $chart->set_tooltip($tooltip);
    return $chart->toPrettyString();
}