티스토리 뷰
728x90
이번 글은 오픈 플래시 차트를 설치한 ("PHP로 오픈 플래시 차트 출력하기" 참조) 이후 각 차트에 대한 실제 모습과 PHP 예제 코드를 참조하기 위해서 작성되었습니다.
3D Bar
srand((double)microtime()*1000000);
$data = array();
// add random height bars:
for( $i=0; $i<10; $i++ )
$data[] = rand(2,9);
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( date("D M d Y") );
$bar = new OFC_Charts_Bar_3d();
$bar->set_values( $data );
$bar->colour = '#D54C78';
$x_axis = new OFC_Elements_Axis_X();
$x_axis->set_3d( 5 );
$x_axis->colour = '#909090';
$x_axis->set_labels( array(1,2,3,4,5,6,7,8,9,10) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $bar );
$chart->set_x_axis( $x_axis );
echo $chart->toPrettyString();
Simple Bar chart
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( date("D M d Y") );
$bar = new OFC_Charts_Bar();
$bar->set_values( array(9,8,7,6,5,4,3,2,1) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $bar );
echo $chart->toPrettyString();
Line
require_once('OFC/OFC_Chart.php');
// generate some random data
srand((double)microtime()*1000000);
$data_1 = array();
$data_2 = array();
$data_3 = array();
for( $i=0; $i<9; $i++ )
{
$data_1[] = rand(1,6);
$data_2[] = rand(7,13);
$data_3[] = rand(14,19);
}
$line_dot = new OFC_Charts_Line_Dot();
$line_dot->set_width( 4 );
$line_dot->set_colour( '#DFC329' );
$line_dot->set_dot_size( 5 );
$line_dot->set_values( $data_1 );
$line_hollow = new OFC_Charts_Line_Hollow();
$line_hollow->set_width( 1 );
$line_hollow->set_colour( '#6363AC' );
$line_hollow->set_dot_size( 5 );
$line_hollow->set_values( $data_2 );
$line = new OFC_Charts_Line();
$line->set_width( 1 );
$line->set_colour( '#5E4725' );
$line->set_dot_size( 5 );
$line->set_values( $data_3 );
$y = new OFC_Elements_Axis_Y();
$y->set_range( 0, 20, 5 );
$chart = new OFC_Chart();
$chart->set_title( new OFC_Elements_Title( 'Three lines example' ) );
$chart->set_y_axis( $y );
//
// here we add our data sets to the chart:
//
$chart->add_element( $line_dot );
$chart->add_element( $line_hollow );
$chart->add_element( $line );
echo $chart->toPrettyString();
Glass Bar
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( date("D M d Y") );
$bar = new OFC_Charts_Bar_Glass();
$bar->set_values( array(9,8,7,6,5,4,3,2,1) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $bar );
echo $chart->toString();
수평 Bar
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( "Our New House Schedule" );
$hbar = new OFC_Charts_Bar_Horizontal();
$hbar->append_value( new OFC_Charts_Bar_Horizontal_Value(0,4) );
$hbar->append_value( new OFC_Charts_Bar_Horizontal_Value(4,8) );
$hbar->append_value( new OFC_Charts_Bar_Horizontal_Value(8,11) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $hbar );
$chart->add_y_axis( new OFC_Elements_Axis_Y() );
$x = new OFC_Elements_Axis_X();
$x->set_offset( false );
$x->set_labels_from_array( array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') );
$chart->set_x_axis( $x );
$y = new OFC_Elements_Axis_Y();
$y->set_offset( true );
$y->set_labels( array( "Make garden look sexy","Paint house","Move into house" ) );
$chart->add_y_axis( $y );
echo $chart->toPrettyString();
Area hollow
$data = array();
for( $i=0; $i<6.2; $i+=0.2 )
{
$tmp = sin($i) * 1.9;
$data[] = $tmp;
}
require_once('OFC/OFC_Chart.php');
$chart = new OFC_Chart();
$chart->set_title( new OFC_Elements_Title( 'Area Hollow Chart' ) );
//
// Make our area chart:
//
$area = new OFC_Charts_Area_Hollow();
// set the circle line width:
$area->set_width( 1 );
$area->set_values( $data );
// add the area object to the chart:
$chart->add_element( $area );
$y_axis = new OFC_Elements_Axis_Y();
$y_axis->set_range( -2, 2, 2 );
$y_axis->labels = null;
$y_axis->set_offset( false );
$x_axis = new OFC_Elements_Axis_X();
$x_axis->labels = $data;
$x_axis->set_steps( 2 );
$x_labels = new OFC_Elements_Axis_X_Label_Set();
$x_labels->set_steps( 4 );
$x_labels->set_vertical();
// Add the X Axis Labels to the X Axis
$x_axis->set_labels( $x_labels );
$chart->add_y_axis( $y_axis );
$chart->x_axis = $x_axis;
echo $chart->toPrettyString();
Pie
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( 'Pie Chart' );
$pie = new OFC_Charts_Pie();
$pie->set_start_angle( 35 );
$pie->set_animate( true );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $pie );
$chart->x_axis = null;
echo $chart->toPrettyString();
Scatter
require_once('OFC/OFC_Chart.php');
$chart = new OFC_Chart();
$title = new OFC_Elements_Title( date("D M d Y") );
$chart->set_title( $title );
$scatter = new OFC_Charts_Scatter( '#FFD600', 10 );
$scatter->set_values(
array(
new OFC_Charts_Scatter_Value( 0, 0 )
)
);
$chart->add_element( $scatter );
//
// plot a circle
//
$s2 = new OFC_Charts_Scatter( '#D600FF', 3 );
$v = array();
for( $i=0; $i<360; $i+=5 )
{
$v[] = new OFC_Charts_Scatter_Value(
number_format(sin(deg2rad($i)), 2, '.', ''),
number_format(cos(deg2rad($i)), 2, '.', '') );
}
$s2->set_values( $v );
$chart->add_element( $s2 );
$x = new OFC_Elements_Axis_X();
$x->set_range( -2, 2 );
$chart->set_x_axis( $x );
$y = new OFC_Elements_Axis_Y();
$y->set_range( -2, 2 );
$chart->add_y_axis( $y );
echo $chart->toPrettyString();
Sketch Bar
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( date("D M d Y") );
$title->set_style( '{color: #567300; font-size: 14px}' );
$bar = new OFC_Charts_Bar_Sketch( '#81AC00', '#567300', 5 );
$bar->set_values( array(9,8,7,6,5,4,3,2,1) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $bar );
echo $chart->toPrettyString();
Stacked Bar
require_once('OFC/OFC_Chart.php');
$title = new OFC_Elements_Title( date("D M d Y") );
$bar_stack = new OFC_Charts_Bar_Stack();
$bar_stack->append_stack( array( 2.5, 5 ) );
$bar_stack->append_stack( array( 7.5 ) );
$bar_stack->append_stack( array( 5, new OFC_Charts_Bar_Stack_Value(5, '#ff0000') ) );
$bar_stack->append_stack( array( 2, 2, 2, 2, new OFC_Charts_Bar_Stack_Value(2, '#ff00ff') ) );
$y = new OFC_Elements_Axis_Y();
$y->set_range( 0, 14, 7 );
$x = new OFC_Elements_Axis_X();
$x->set_labels( array( 'a', 'b', 'c', 'd' ) );
$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $bar_stack );
$chart->set_x_axis( $x );
$chart->add_y_axis( $y );
echo $chart->toPrettyString();
728x90
'프로그래밍' 카테고리의 다른 글
| PHP 플래시 차트 출력의 실제 (2) | 2016.04.08 |
|---|---|
| 올림피아드 기출문제로 배우는 C언어 - 배열와 포인터 (0) | 2016.04.07 |
| PHP로 오픈 플래시 차트 출력하기 (6) | 2016.04.06 |
| 올림피아드 기출문제로 배우는 C언어 - 함수 (0) | 2016.04.04 |
| 올림피아드 기출문제로 배우는 C언어 - 수열의 합 (0) | 2016.04.01 |
댓글