JBTALKS.CC
标题:
[疑问]simple html dom + open flash chart
[打印本页]
作者:
alanlai12345
时间:
2010-12-31 01:53 AM
标题:
[疑问]simple html dom + open flash chart
Below is my code for obtaining the data file :
require_once("simple_html_dom.php");
$html=file_get_html("http://finance.yahoo.com/q/hp?s=4707.KL+Historical+Prices");
foreach ($html->find('td[class=yfnc_tabledata1]') as $e)
echo $e->innertext . '<br />' ;
复制代码
This is my code for output the "preset" data into open flash chart :
<?php
include 'php-ofc-library/open-flash-chart.php';
$month = array();
$price = array();
$month[] = 'Jan 4'; $price[] = 36.7;
$month[] = 'Feb 2'; $price[] = 38.7;
$month[] = 'Mar 1'; $price[] = 42.8;
$month[] = 'Apr 1'; $price[] = 38.2;
$month[] = 'May 3'; $price[] = 37.8;
$month[] = 'Jun 1'; $price[] = 34.7;
$month[] = 'Jul 1'; $price[] = 38.4;
$month[] = 'Aug 2'; $price[] = 40.2;
$month[] = 'Sep 1'; $price[] = 39.5;
$month[] = 'Oct 1'; $price[] = 40.3;
$month[] = 'Nov 1'; $price[] = 45.9;
$month[] = 'Dec 1'; $price[] = 48.9;
$chart = new open_flash_chart();
$title = new title( 'Nestle (M) SDN BHD' );
$title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
$chart->set_title( $title );
$area = new area();
$area->set_colour( '#5B56B6' );
$area->set_values( $price );
$area->set_key( 'Share Price(RM)/unit', 12 );
$chart->add_element( $area );
$x_labels = new x_axis_labels();
$x_labels->set_steps(1);
$x_labels->set_vertical();
$x_labels->set_colour( '#A2ACBA' );
$x_labels->set_labels( $month );
$x = new x_axis();
$x->set_colour( '#A2ACBA' );
$x->set_grid_colour( '#D7E4A3' );
$x->set_offset( false );
$x->set_steps(1);
// Add the X Axis Labels to the X Axis
$x->set_labels( $x_labels );
$chart->set_x_axis( $x );
$x_legend = new x_legend( '1 year graph' );
$x_legend->set_style( '{font-size: 20px; color: #778877}' );
$chart->set_x_legend( $x_legend );
$y = new y_axis();
$y->set_range( 0, 60, 20 );
$chart->add_y_axis( $y );
echo $chart->toPrettyString();
复制代码
请问有什么方法能把两个combine起来?也就是说我能利用simple_html_dom取回来的资料来output在我的open flash chart 上?由于我的flash chart‘s output是根据我preset data,但是我想要让flash chart’s output是依据我用simple-html-dom取回来的资料。请问要怎样才能做到呢?
作者:
Super-Tomato
时间:
2010-12-31 12:22 PM
只要你去摸索如何把
http://finance.yahoo.com/q/hp?s=4707.KL+Historical+Prices
所得到的資料编排成
# $month = array();
# $price = array();
# $month[] = 'Jan 4'; $price[] = 36.7;
# $month[] = 'Feb 2'; $price[] = 38.7;
# $month[] = 'Mar 1'; $price[] = 42.8;
# $month[] = 'Apr 1'; $price[] = 38.2;
# $month[] = 'May 3'; $price[] = 37.8;
# $month[] = 'Jun 1'; $price[] = 34.7;
# $month[] = 'Jul 1'; $price[] = 38.4;
# $month[] = 'Aug 2'; $price[] = 40.2;
# $month[] = 'Sep 1'; $price[] = 39.5;
# $month[] = 'Oct 1'; $price[] = 40.3;
# $month[] = 'Nov 1'; $price[] = 45.9;
# $month[] = 'Dec 1'; $price[] = 48.9;
這样的資料型态就可以了啊
作者:
vampcheah
时间:
2011-1-1 10:52 AM
把你的innertext 稍微处理就好~
作者:
alanlai12345
时间:
2011-1-2 06:28 PM
谢谢两位,我是用for loop + array()来解决了。
include 'php-ofc-library/open-flash-chart.php';
$month = array();
$price = array();
require_once("simple_html_dom.php");
$html=file_get_html("http://finance.yahoo.com/q/hp?s=4707.KL+Historical+Prices");
for ($i=336; $i>=0; $i-=7)
{
$month[] = $html->find('td[class="yfnc_tabledata1"]', $i)->innertext;
}
for ($j=340; $j>=4; $j-=7)
{
$price[] = floatval($html->find('td[class="yfnc_tabledata1"]', $j)->innertext);
}
复制代码
欢迎光临 JBTALKS.CC (https://jbtalks.my/)
Powered by Discuz! X2.5