注册  找回密码

JBTALKS.CC


查看: 2503|回复: 3

[疑问]simple html dom + open flash chart

 关闭 [复制链接]

2

主题

0

好友

39

积分

初级会员

Rank: 1

发表于 2010-12-31 01:53 AM |显示全部楼层
Below is my code for obtaining the data file :

  1. require_once("simple_html_dom.php");
  2. $html=file_get_html("http://finance.yahoo.com/q/hp?s=4707.KL+Historical+Prices");
  3. foreach ($html->find('td[class=yfnc_tabledata1]') as $e)
  4.         echo $e->innertext . '<br />' ;
  5.        
复制代码
This is my code for output the "preset" data into open flash chart :

  1. <?php
  2. include 'php-ofc-library/open-flash-chart.php';

  3. $month = array();
  4. $price = array();
  5. $month[] = 'Jan 4'; $price[] = 36.7;
  6. $month[] = 'Feb 2'; $price[] = 38.7;
  7. $month[] = 'Mar 1'; $price[] = 42.8;
  8. $month[] = 'Apr 1'; $price[] = 38.2;
  9. $month[] = 'May 3'; $price[] = 37.8;
  10. $month[] = 'Jun 1'; $price[] = 34.7;
  11. $month[] = 'Jul 1'; $price[] = 38.4;
  12. $month[] = 'Aug 2'; $price[] = 40.2;
  13. $month[] = 'Sep 1'; $price[] = 39.5;
  14. $month[] = 'Oct 1'; $price[] = 40.3;
  15. $month[] = 'Nov 1'; $price[] = 45.9;
  16. $month[] = 'Dec 1'; $price[] = 48.9;

  17. $chart = new open_flash_chart();

  18. $title = new title( 'Nestle (M) SDN BHD' );
  19. $title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
  20. $chart->set_title( $title );

  21. $area = new area();
  22. $area->set_colour( '#5B56B6' );
  23. $area->set_values( $price );
  24. $area->set_key( 'Share Price(RM)/unit', 12 );
  25. $chart->add_element( $area );

  26. $x_labels = new x_axis_labels();
  27. $x_labels->set_steps(1);
  28. $x_labels->set_vertical();
  29. $x_labels->set_colour( '#A2ACBA' );
  30. $x_labels->set_labels( $month );

  31. $x = new x_axis();
  32. $x->set_colour( '#A2ACBA' );
  33. $x->set_grid_colour( '#D7E4A3' );
  34. $x->set_offset( false );
  35. $x->set_steps(1);
  36. // Add the X Axis Labels to the X Axis
  37. $x->set_labels( $x_labels );

  38. $chart->set_x_axis( $x );

  39. $x_legend = new x_legend( '1 year graph' );
  40. $x_legend->set_style( '{font-size: 20px; color: #778877}' );
  41. $chart->set_x_legend( $x_legend );

  42. $y = new y_axis();
  43. $y->set_range( 0, 60, 20 );
  44. $chart->add_y_axis( $y );

  45. echo $chart->toPrettyString();
复制代码
请问有什么方法能把两个combine起来?也就是说我能利用simple_html_dom取回来的资料来output在我的open flash chart 上?由于我的flash chart‘s output是根据我preset data,但是我想要让flash chart’s output是依据我用simple-html-dom取回来的资料。请问要怎样才能做到呢?






7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

发表于 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;

這样的資料型态就可以了啊






回复

使用道具 举报

6

主题

1

好友

745

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

发表于 2011-1-1 10:52 AM |显示全部楼层
把你的innertext 稍微处理就好~






回复

使用道具 举报

2

主题

0

好友

39

积分

初级会员

Rank: 1

发表于 2011-1-2 06:28 PM |显示全部楼层
谢谢两位,我是用for loop + array()来解决了。
  1. include 'php-ofc-library/open-flash-chart.php';
  2. $month = array();
  3. $price = array();
  4. require_once("simple_html_dom.php");
  5. $html=file_get_html("http://finance.yahoo.com/q/hp?s=4707.KL+Historical+Prices");
  6.        
  7.         for ($i=336; $i>=0; $i-=7)
  8.         {
  9.                 $month[] = $html->find('td[class="yfnc_tabledata1"]', $i)->innertext;
  10.                 }
  11.        
  12.         for ($j=340; $j>=4; $j-=7)
  13.         {
  14.                 $price[] = floatval($html->find('td[class="yfnc_tabledata1"]', $j)->innertext);
  15.                
  16.                 }
复制代码






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-4-19 03:23 AM , Processed in 0.101822 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Thanks to ImageShack for Free Image Hosting
Ultra High-speed web hosting powered by iCore Technology Sdn. Bhd.
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | JBTALKS部落 | ICORE TECHNOLOGY SDN. BHD. | GXUnlimited-ECSHOP | TM UniFi | TM Streamyx | TM Fixed Line
www.jbtalks.cc | mobile.jbtalks.cc | www.jbtalks.com | www.jbtalks.my | www.icore.com.my | www.icorehosting.com | www.icorehosting.net | www.cttsite.com | www.icore.my | www.lpohchin.com
bbs.jbtalks.cc | bbs.jbtalks.com | bbs.jbtalks.my | bbs.jbtalks.com
回顶部