amCharts [股票]图表

发布于 2024-11-27 00:43:36 字数 615 浏览 7 评论 0原文

我一直在使用 amCharts 股票图表来显示来自雅虎财经 .csv 文件的数据,该文件以这种格式显示数据:(有效)

Date,Open,High,Low,Close,Volume,Adj Close
2011-07-27,617.18,620.95,604.75,607.22,3934400,607.22
2011-07-26,618.05,627.50,617.22,622.52,2342900,622.52
2011-07-25,613.36,625.41,613.00,618.98,3131600,618.98

但是现在我需要从 Google 财经获取数据,他们将数据格式化为这种格式(不工作)。

Date,Open,High,Low,Close,Volume
28-Jul-11,36.02,36.84,36.01,36.42,8870180
27-Jul-11,36.71,36.86,35.98,36.06,10395443
26-Jul-11,37.26,37.27,36.80,36.86,6366097

我相信雅虎和谷歌之间的数据格式不同是导致 amChart 不显示任何数字的原因,因为它无法读取文件。

如何格式化日期以使其正确读取值?

I've been using amCharts stocks charts to display data from Yahoo Finance .csv file which displays data in this format: (which works)

Date,Open,High,Low,Close,Volume,Adj Close
2011-07-27,617.18,620.95,604.75,607.22,3934400,607.22
2011-07-26,618.05,627.50,617.22,622.52,2342900,622.52
2011-07-25,613.36,625.41,613.00,618.98,3131600,618.98

However now I need to get data from Google finance and they format they're data in this format (which isn't working).

Date,Open,High,Low,Close,Volume
28-Jul-11,36.02,36.84,36.01,36.42,8870180
27-Jul-11,36.71,36.86,35.98,36.06,10395443
26-Jul-11,37.26,37.27,36.80,36.86,6366097

I believe the data format different between Yahoo and Google is what's causing the amChart to not display any figures because it can't read the file.

How do I format the date to get it to read the values properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸 2024-12-04 00:43:36

我假设您使用的是 amstock 图表 1.4.0.1。在 amstock_settings.xml 中,您需要编辑日期格式设置。默认情况下,它使用 YYYY-MM-DD,我根据您的示例假设这是雅虎财经 CSV 中的默认日期格式。 Google 财经的日期格式为 DD-Mon-YY,根据 AmCharts,“Mon”不是有效符号。您可以尝试将设置更改为DD-Mon-YY,看看它是否有效,如果不行,您可能需要使用程序(例如java)将csv中的日期值更改为YYYY-MM-DD。

<!-- [YYYY-MM-DD] (date format) The valid symbols are: YYYY, MM, DD, hh, mm, ss, fff. Any order
     and separators can be used, for example: DD-MM-YYYY, YYYY-MM, YYYY-DD-MM hh, 
     DD-MM-YY hh:mm:ss, etc. fff means milliseconds. In case you use miliseconds, you must provide the
     3 digit number -->
     <date_format>YYYY-MM-DD</date_format>

I'll assume that you are using amstock charts 1.4.0.1. In your amstock_settings.xml you need to edit the date format settings. By default it is using YYYY-MM-DD which I assume based from your example is Yahoo Finance's default date format in their CSV. Google finance's date format is DD-Mon-YY which based on AmCharts 'Mon' is not a valid symbol. You can try to change the settings to DD-Mon-YY and see if it works if not you may need to use a program(e.g. java) to change the date values in csv into YYYY-MM-DD.

<!-- [YYYY-MM-DD] (date format) The valid symbols are: YYYY, MM, DD, hh, mm, ss, fff. Any order
     and separators can be used, for example: DD-MM-YYYY, YYYY-MM, YYYY-DD-MM hh, 
     DD-MM-YY hh:mm:ss, etc. fff means milliseconds. In case you use miliseconds, you must provide the
     3 digit number -->
     <date_format>YYYY-MM-DD</date_format>
空‖城人不在 2024-12-04 00:43:36

amStock 不支持 28-Jul-11 格式的日期。您需要构建一个服务器端代理脚本,将所有日期转换为某种受支持的格式,例如 2011-07-28。

这是 PHP 中的一个:

<?php
// get input data (replace with the actual data)
// i.e.: $input = file_get_contents('http://...........');
$input = "Date,Open,High,Low,Close,Volume
28-Jul-11,36.02,36.84,36.01,36.42,8870180
27-Jul-11,36.71,36.86,35.98,36.06,10395443
26-Jul-11,37.26,37.27,36.80,36.86,6366097";

// parse line by line
$lines = preg_split("/\r\n|\r|\n/", $input);
$cnt = sizeof($lines);
for ($i = 0; $i < $cnt; $i++) {
  $cols = explode(',', $lines[$i]);
  if ($date = strtotime($cols[0])) {
    $cols[0] = date('Y-m-d', $date);
    $lines[$i] = implode(',', $cols);
  }
}

// output
header('Content-Type: text/csv');
echo implode("\r\n", $lines);
?>

amStock does not support dates in 28-Jul-11 format. You will need to build a server-side proxy script that converts all dates to some supported format like 2011-07-28.

Here's one in PHP:

<?php
// get input data (replace with the actual data)
// i.e.: $input = file_get_contents('http://...........');
$input = "Date,Open,High,Low,Close,Volume
28-Jul-11,36.02,36.84,36.01,36.42,8870180
27-Jul-11,36.71,36.86,35.98,36.06,10395443
26-Jul-11,37.26,37.27,36.80,36.86,6366097";

// parse line by line
$lines = preg_split("/\r\n|\r|\n/", $input);
$cnt = sizeof($lines);
for ($i = 0; $i < $cnt; $i++) {
  $cols = explode(',', $lines[$i]);
  if ($date = strtotime($cols[0])) {
    $cols[0] = date('Y-m-d', $date);
    $lines[$i] = implode(',', $cols);
  }
}

// output
header('Content-Type: text/csv');
echo implode("\r\n", $lines);
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文