更新:添加每日和每月数据选项,修改相关URL参数,更新JavaScript文件,增加股票指数历史数据获取功能

This commit is contained in:
杨水淼
2025-07-09 07:36:50 +08:00
parent 5d135b24f1
commit 43a202c789
12 changed files with 734 additions and 53 deletions
+12 -1
View File
@@ -1,4 +1,12 @@
<?php
/*
* @Author: Yangshuimiao
* @Date: 2023-06-25 12:26:16
* @LastEditTime: 2025-02-13 17:04:36
* @FilePath: \chartFore.php
* @Description:
* Copyright 2025 Yangshuimiao, All Rights Reserved.
*/
#查询个股价格对应PE_TTM, PB, PS的长期趋势数据
include_once "inc/getBasic.inc.php" ;
include_once "inc/getData.inc.php";
@@ -9,9 +17,12 @@ $day_end=($_REQUEST['e']=='')?date('Ymd'):$_REQUEST['e'];
$item = ($_REQUEST['item']=='')?'pe_ttm':$_REQUEST['item'];
$unit = ''; # Without a unit on PE
$data = getStockHist($ts_code,$day_st,$day_end);
#$data = getIndexHistoryDataByTS($ts_code, $day_st, $day_end);
$data2 = getBasicData($ts_code,$day_st,$day_end,$item);
#$data2 = getStockHistoryDataByTS($ts_code, $day_st, $day_end, $item);
#var_dump($data2['data']);
//print_r($data2);
//print_r($data);
$subtext_ext = "Max: ".$data2['data_max'];
$subtext_ext .= ", Min: ".$data2['data_min'];
$subtext_ext .= ", Average: ".$data2['data_avg'];
+56
View File
@@ -0,0 +1,56 @@
<?php
$_REQUEST['code']=$_REQUEST['code']?$_REQUEST['code']:'sh'; #code:sh sz zx cy
$_REQUEST['t_start']=$_REQUEST['t_start']?$_REQUEST['t_start']:'2015-01-01';
$_REQUEST['t_end']=$_REQUEST['t_end']?$_REQUEST['t_end']:'';
$title="指数VS PE/PB/PS/市值 趋势";
include_once "html/head.php";
?>
<form name="main" id="main" method="get"> <div style="width:100%;text-align:center">
指数代码:
<select name='code' id='code'>
<option value='sh'>上证指数</option>
<option value='sz'>深圳成指</option>
<option value='zx'>中小板指</option>
<option value='cy'>创业板指</option>
</select>&nbsp;
<script>
document.getElementById('code').value='<?=$_REQUEST['code']?>';
</script>
开始时间: <input type='date' name='t_start' id='t_start' width='30px' value='<?=$_REQUEST['t_start']?>' >
结束时间: <input type='date' name='t_end' id='t_end' width='30px' value='<?=$_REQUEST['t_end']?>' >
<input type='submit' value="给我查!">
<div >&nbsp;</div>
<input type='checkbox' id='cb_pe' onclick="hideSwitch(this.id,'pe_ttm')" checked> PE_TTM 市盈率
<input type='checkbox' id='cb_pb' onclick="hideSwitch(this.id,'pb')" > PB 市净率
<input type='checkbox' id='cb_ps' onclick="hideSwitch(this.id,'ps')" > PS 市销率
<input type='checkbox' id='cb_total_mv' onclick="hideSwitch(this.id,'total_mv')" > 总市值
<input type='checkbox' id='cb_circ_mv' onclick="hideSwitch(this.id,'circ_mv')" > 流通市值
</div> </form>
<div >&nbsp;</div>
<!--https://echart.doorcome.cn/chartFive.php?s=20071001&code=sz&item=total_mv-->
<div style="width:100%; text-align:center" id='pe_ttm'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=pe_ttm&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='pb'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=pb&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='ps'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=ps&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='total_mv'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=total_mv&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='circ_mv'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=circ_mv&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<?php include_once "html/footer.php"; ?>
+1
View File
@@ -9,6 +9,7 @@ $title="二手房每日新增挂牌量({$subTitle})";
$urlAppend = "t=esfListDaily&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
$urlAppend .= "&district={$_REQUEST['district']}";
$urlAppend .= "&dm=Daily";
$url = 'https://echart.doorcome.cn/inc/ajax.inc.php?'.$urlAppend;
include_once "html/head.php";
?>
+33 -3
View File
@@ -2,6 +2,10 @@
require_once "inc/functions.inc.php";
$_REQUEST['t_start']=$_REQUEST['t_start']?$_REQUEST['t_start']:'2023-08-15';
$_REQUEST['t_end']=$_REQUEST['t_end']?$_REQUEST['t_end']:date('Y-m-d');
$_REQUEST['mst']=$_REQUEST['mst']?$_REQUEST['mst']:'2023-08';
$_REQUEST['med']=$_REQUEST['med']?$_REQUEST['med']:date('Y-m');
$_REQUEST['dm']=$_REQUEST['dm']?$_REQUEST['dm']:'Daily';
$_REQUEST['district']=$_REQUEST['district']?$_REQUEST['district']:'合计';
$subTitle=($_REQUEST['district']=='合计')?'宁波地区':$_REQUEST['district'];
$title="新房V.S二手房每日成交量({$subTitle})";
@@ -9,27 +13,53 @@ $title1="新房每日成交量({$subTitle})";
$title2="二手房每日成交量({$subTitle})";
$urlAppend = "t=newTBD&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
$urlAppend = "t=newTBD";
if($_REQUEST['dm']=='Daily') $urlAppend.="&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
if($_REQUEST['dm']=='Monthly') $urlAppend.="&t_start={$_REQUEST['mst']}&t_end={$_REQUEST['med']}";
$urlAppend .= "&district={$_REQUEST['district']}";
$urlAppend .= "&dm={$_REQUEST['dm']}";
$url = 'https://echart.doorcome.cn/inc/ajax.inc.php?'.$urlAppend;
$urlAppend2 = "t=esfTBD&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
$urlAppend2 = "t=esfTBD";
if($_REQUEST['dm']=='Daily') $urlAppend2.="&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
if($_REQUEST['dm']=='Monthly') $urlAppend2.="&t_start={$_REQUEST['mst']}&t_end={$_REQUEST['med']}";
$urlAppend2 .= "&district={$_REQUEST['district']}";
$urlAppend2 .= "&dm={$_REQUEST['dm']}";
$url2 = 'https://echart.doorcome.cn/inc/ajax.inc.php?'.$urlAppend2;
include_once "html/head.php";
?>
<form name="main" id="main" method="get"> <div style="width:100%;text-align:center">
区域:
<?php districtList(); ?>
<?php districtList(); ?>&nbsp;&nbsp;
Daily/Monthly:
<?php byDM('dm','dblock','mblock'); ?> &nbsp;&nbsp;
<span style="display:inline;" id='dblock'>
开始时间: <input type='date' name='t_start' id='t_start' width='30px' >
结束时间: <input type='date' name='t_end' id='t_end' width='30px' >
</span>
<span style="display:None;" id='mblock'>
开始月份: <input type="month" name='mst' id='mst' >&nbsp;&nbsp;
结束月份: <input type="month" name='med' id='med' >
</span>
<input type='submit' value="给我查!">
<div >&nbsp;</div>
<script>
$("#district").val('<?=$_REQUEST['district']?>');
$("#t_start").val('<?=$_REQUEST['t_start']?>');
$("#t_end").val('<?=$_REQUEST['t_end']?>');
$("#mst").val('<?=$_REQUEST['mst']?>');
$("#med").val('<?=$_REQUEST['med']?>');
$("#dm").val('<?=$_REQUEST['dm']?>');
var vdm= $('#dm').val();
if(vdm=='Monthly'){
$('#dblock').css('display','none');
$('#mblock').css('display','inline');
}
if(vdm=='Daily'){
$('#dblock').css('display','inline');
$('#mdblock').css('display','none');
}
</script>
</div> </form>
<div >&nbsp;</div>
+39 -2
View File
@@ -1,29 +1,66 @@
<?php
/*
* @Author: Yangshuimiao
* @Date: 2023-08-21 21:14:00
* @LastEditTime: 2025-01-21 10:05:30
* @FilePath: \estateTradeDaily.php
* @Description:
* Copyright 2025 Yangshuimiao, All Rights Reserved.
*/
require_once "inc/functions.inc.php";
$_REQUEST['t_start']=$_REQUEST['t_start']?$_REQUEST['t_start']:'2023-08-15';
$_REQUEST['t_end']=$_REQUEST['t_end']?$_REQUEST['t_end']:date('Y-m-d');
//$currentYear = date('Y');
$_REQUEST['mst']=$_REQUEST['mst']?$_REQUEST['mst']:'2023-08';
$_REQUEST['med']=$_REQUEST['med']?$_REQUEST['med']:date('Y-m');
$_REQUEST['dm']=$_REQUEST['dm']?$_REQUEST['dm']:'Daily';
$_REQUEST['district']=$_REQUEST['district']?$_REQUEST['district']:'合计';
$subTitle=($_REQUEST['district']=='合计')?'宁波地区':$_REQUEST['district'];
$title="二手房每日成交量({$subTitle})";
$urlAppend = "t=esfTBD&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
$urlAppend = "t=esfTBD";
if($_REQUEST['dm']=='Daily') $urlAppend.="&t_start={$_REQUEST['t_start']}&t_end={$_REQUEST['t_end']}";
if($_REQUEST['dm']=='Monthly') $urlAppend.="&t_start={$_REQUEST['mst']}&t_end={$_REQUEST['med']}";
$urlAppend .= "&district={$_REQUEST['district']}";
$urlAppend .= "&dm={$_REQUEST['dm']}";
$url = 'https://echart.doorcome.cn/inc/ajax.inc.php?'.$urlAppend;
include_once "html/head.php";
?>
<form name="main" id="main" method="get"> <div style="width:100%;text-align:center">
区域:
<?php districtList(); ?>
<?php districtList(); ?>&nbsp;&nbsp;
Daily/Monthly:
<?php byDM('dm','dblock','mblock'); ?> &nbsp;&nbsp;
<span style="display:inline;" id='dblock'>
开始时间: <input type='date' name='t_start' id='t_start' width='30px' >
结束时间: <input type='date' name='t_end' id='t_end' width='30px' >
</span>
<span style="display:None;" id='mblock'>
开始月份: <input type="month" name='mst' id='mst' >&nbsp;&nbsp;
结束月份: <input type="month" name='med' id='med' >
</span>
<input type='submit' value="给我查!">
<div >&nbsp;</div>
<script>
$("#district").val('<?=$_REQUEST['district']?>');
$("#t_start").val('<?=$_REQUEST['t_start']?>');
$("#t_end").val('<?=$_REQUEST['t_end']?>');
$("#mst").val('<?=$_REQUEST['mst']?>');
$("#med").val('<?=$_REQUEST['med']?>');
$("#dm").val('<?=$_REQUEST['dm']?>');
var vdm= $('#dm').val();
if(vdm=='Monthly'){
$('#dblock').css('display','none');
$('#mblock').css('display','inline');
}
if(vdm=='Daily'){
$('#dblock').css('display','inline');
$('#mdblock').css('display','none');
}
</script>
</div> </form>
<div >&nbsp;</div>
+1 -1
View File
@@ -6,7 +6,7 @@
<script type="text/javascript" src="lib/jquery.min.js?version=3.6.0"></script>
<script type="text/javascript" src="/lib/echarts/5.4.2/echarts.js"></script>
<script type="text/javascript" src="/lib/DataTables-2/datatables.min.js"></script>
<script type="text/javascript" src="/js/pubfunc.js?version=0.1"></script>
<script type="text/javascript" src="/js/pubfunc.js?version=0.4"></script>
<link href="css/style.css?version=2000002" rel="stylesheet" type="text/css">
<link href="/lib/DataTables-2/datatables.min.css" rel="stylesheet" type="text/css">
<title><?=$title?></title>
+110 -7
View File
@@ -94,8 +94,8 @@ if($_REQUEST['t']=='esfListDaily'){
}
function esfTradeDaily(){
global $mysqli;
$sql= <<<EOF
if($_REQUEST['dm']=='Daily'){
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m-%d') td,
@@ -110,6 +110,32 @@ function esfTradeDaily(){
where ej.data_type='5' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
order by ej.tdate asc
EOF;
}
if($_REQUEST['dm']=='Monthly'){
$where="";
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
if($_REQUEST['t_end']) {
$endDate = new DateTime($_REQUEST['t_end']);
$endDate->modify('last day of this month');
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
}
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m') td,
eje.val district,
sum(eje1.val) qty,
sum(eje2.val) area
FROM
`estate_json` ej
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+4
where ej.data_type='5' {$where}
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
EOF;
//echo $sql;
}
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
@@ -118,8 +144,8 @@ EOF;
function esfListDaily(){
global $mysqli;
$sql= <<<EOF
if($_REQUEST['dm']=='Daily'){
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m-%d') td,
@@ -134,7 +160,32 @@ function esfListDaily(){
where ej.data_type='8' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
order by ej.tdate asc
EOF;
}
if($_REQUEST['dm']=='Monthly'){
$where="";
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
if($_REQUEST['t_end']) {
$endDate = new DateTime($_REQUEST['t_end']);
$endDate->modify('last day of this month');
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
}
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m') td,
eje.val district,
sum(eje1.val) qty,
sum(eje2.val) price
FROM
`estate_json` ej
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+5
where ej.data_type='8' {$where}
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
EOF;
//echo $sql;
}
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
return $data;
@@ -144,7 +195,7 @@ EOF;
*newTBD: 新房Trade By Day
*/
if($_REQUEST['t']=='newTBD'){
if($_REQUEST['dm']=='Daily'){
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
@@ -158,11 +209,37 @@ if($_REQUEST['t']=='newTBD'){
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+4
where ej.data_type='1' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
order by date_format(tdate,'%Y-%m-%d') asc
EOF;
}
if($_REQUEST['dm']=='Monthly'){
$where="";
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
if($_REQUEST['t_end']) {
$endDate = new DateTime($_REQUEST['t_end']);
$endDate->modify('last day of this month');
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
}
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m') td,
eje.val district,
sum(eje1.val) qty,
sum(eje2.val) area
FROM
`estate_json` ej
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+4
where ej.data_type='1' {$where}
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
EOF;
}
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
if($_REQUEST['dm']=='Daily'){
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
@@ -176,7 +253,33 @@ EOF;
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+4
where ej.data_type='4' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
order by date_format(tdate,'%Y-%m-%d') asc
EOF;
}
if($_REQUEST['dm']=='Monthly'){
$where="";
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
if($_REQUEST['t_end']) {
$endDate = new DateTime($_REQUEST['t_end']);
$endDate->modify('last day of this month');
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
}
$sql= <<<EOF
SELECT
distinct(ej.uuid) uid ,
date_format(tdate,'%Y-%m-%d') td,
eje.val district,
max(eje1.val) area,
max(eje2.val) qty
FROM
`estate_json` ej
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
left join estate_json_ext eje1 on eje1.id=eje.id+3
left join estate_json_ext eje2 on eje2.id=eje.id+4
where ej.data_type='4' $where
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
EOF;
}
$result = $mysqli->query($sql);
$data2 = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(array(
Binary file not shown.
+98
View File
@@ -1,4 +1,5 @@
<?php
include_once __DIR__."/functions.inc.php";
/**
* 获取PE_TTM,PB,PS等历史数据
* @param $ts_code ts code
@@ -312,4 +313,101 @@ function yearToname($year){
return substr($year,4,4);
}
}
// 函数一:获取股票代码ts_code对应的历史pe_ttm、pb或ps
function getStockHistoryDataByTS($ts_code, $day_st, $day_end = null, $item){
//global $token;
// 参数校验
if (empty($ts_code) || empty($day_st) || !in_array(strtolower($item), ['pe_ttm', 'pb', 'ps'])) {
return "参数错误:股票代码、起始日期不能为空,查询项目必须为pe_ttm、pb或ps。";
}
// 处理日期参数
$params = [
"ts_code" => $ts_code,
"start_date" => $day_st,
"end_date" => $day_end ?? date("Y-m-d") // 如果为空,默认为今天
];
// 调用TuShare API获取数据
$data = callTushareApi('daily_basic', $params);
return true ;
if (empty($data)) {
return "未获取到数据,请检查参数或网络连接。";
}
// 提取指定项目的数据
$result = [];
$tDate = [];
$itemValues = [];
foreach ($data as $row) {
$tDate[] = $row['trade_date'];
$itemValues[] = $row[$item];
}
// 按日期排序(从远到近,默认已经是按日期排序的)
$tDate = array_reverse($tDate); // 默认TuShare按日期顺序是近到远,所以反转得到远到近
$itemValues = array_reverse($itemValues);
// 计算统计值
$dataMax = max($itemValues);
$dataMin = min($itemValues);
$dataAvg = array_sum($itemValues) / count($itemValues);
$dataLast = end($itemValues);
// 返回结果
return [
'tDate' => $tDate,
'data' => $itemValues,
'data_max' => $dataMax,
'data_min' => $dataMin,
'data_avg' => $dataAvg,
'data_last' => $dataLast
];
}
// 函数二:获取指数趋势历史数据
function getIndexHistoryDataByTS($ts_code, $day_st, $day_end = null)
{
global $token;
// 参数校验
if (empty($ts_code) || empty($day_st)) {
return "参数错误:股票代码和起始日期不能为空。";
}
// 处理日期参数
$params = [
"ts_code" => $ts_code,
"start_date" => $day_st,
"end_date" => $day_end ?? date("Y-m-d") // 如果为空,默认为今天
];
// 调用TuShare API获取数据
$data = callTushareApi('index_dailybasic', $params);
return true ;
if (empty($data)) {
return "未获取到数据,请检查参数或网络连接。";
}
// 提取指数点数值
$tDate = [];
$closeValues = [];
foreach ($data as $row) {
$tDate[] = $row['trade_date'];
$closeValues[] = $row['close']; // 假设close字段是指数点数值
}
// 按日期排序
$tDate = array_reverse($tDate);
$closeValues = array_reverse($closeValues);
// 返回结果
return [
'tDate' => $tDate,
'data' => $closeValues
];
}
?>
+185 -38
View File
@@ -1,56 +1,203 @@
<?php
$_REQUEST['code']=$_REQUEST['code']?$_REQUEST['code']:'sh'; #code:sh sz zx cy
$_REQUEST['t_start']=$_REQUEST['t_start']?$_REQUEST['t_start']:'2015-01-01';
$_REQUEST['t_end']=$_REQUEST['t_end']?$_REQUEST['t_end']:'';
$title="指数VS PE/PB/PS/市值 趋势";
include_once "html/head.php";
$_REQUEST['code'] = $_REQUEST['code']?$_REQUEST['code']:'000001.SH';
$_REQUEST['t_start']= $_REQUEST['t_start']?$_REQUEST['t_start']:'2020-01-01';
$_REQUEST['t_end'] = $_REQUEST['t_end']?$_REQUEST['t_end']:date('Y-m-d');
$ts_code = $_REQUEST['code'];
?>
<form name="main" id="main" method="get"> <div style="width:100%;text-align:center">
指数代码:
<select name='code' id='code'>
<option value='sh'>上证指数</option>
<option value='sz'>深圳成指</option>
<option value='zx'>中小板指</option>
<option value='cy'>创业板指</option>
<option value='000001.SH'>上证指数</option>
<option value='399001.SZ'>深圳成指</option>
<option value='399005.SZ'>中小板指</option>
<option value='399006.SZ'>创业板指</option>
<option value='000016.SZ'>上证50</option>
<option value='399300.SZ'>沪深300</option>
<option value='399905.SZ'>中证500</option>
</select>&nbsp;
<script>
document.getElementById('code').value='<?=$_REQUEST['code']?>';
$('#code').val('<?=$_REQUEST['code']?>');
</script>
开始时间: <input type='date' name='t_start' id='t_start' width='30px' value='<?=$_REQUEST['t_start']?>' >
结束时间: <input type='date' name='t_end' id='t_end' width='30px' value='<?=$_REQUEST['t_end']?>' >
<input type='submit' value="给我查!">
<div >&nbsp;</div>
<input type='checkbox' id='cb_pe' onclick="hideSwitch(this.id,'pe_ttm')" checked> PE_TTM 市盈率
<input type='checkbox' id='cb_pb' onclick="hideSwitch(this.id,'pb')" > PB 市净率
<input type='checkbox' id='cb_ps' onclick="hideSwitch(this.id,'ps')" > PS 市销率
<input type='checkbox' id='cb_total_mv' onclick="hideSwitch(this.id,'total_mv')" > 总市值
<input type='checkbox' id='cb_circ_mv' onclick="hideSwitch(this.id,'circ_mv')" > 流通市值
<input type='checkbox' id='cb_pb' onclick="hideSwitch(this.id,'pb')" checked> PB 市净率
<input type='checkbox' id='cb_total_mv' onclick="hideSwitch(this.id,'total_mv')" checked> 总市值
</div> </form>
<div >&nbsp;</div>
<!--https://echart.doorcome.cn/chartFive.php?s=20071001&code=sz&item=total_mv-->
<div style="width:100%; text-align:center" id='pe_ttm'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=pe_ttm&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='pb'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=pb&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='ps'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=ps&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='total_mv'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=total_mv&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<div >&nbsp;</div>
<div style="width:100%; text-align:center; display:None;" id='circ_mv'>
<iframe src="https://echart.doorcome.cn/chartFive.php?s=<?=$_REQUEST['t_start']?>&item=circ_mv&code=<?=$_REQUEST['code']?>&e=<?=$_REQUEST['t_end']?>"
height="400px" width="1000px"></iframe>
</div>
<?php include_once "html/footer.php"; ?>
<!-- 图表容器 -->
<div id="pe_ttm" style="width: 1000px; height:400px; margin: 0 auto 20px;"></div>
<div id="pb" style="width: 1000px; height:400px; margin: 0 auto 20px;"></div>
<div id="total_mv" style="width: 1000px; height:400px; margin: 0 auto 20px;"></div>
<script>
let start_date=formatDateToYYYYMMDD("<?=$_REQUEST['t_start'] ?>");
let end_date=formatDateToYYYYMMDD("<?=$_REQUEST['t_end'] ?>");
url = "https://api.doorcome.cn/api/indexDatas/?tscode=<?=$_REQUEST['code'] ?>";
url += "&start_date="+start_date+"&end_date="+end_date;
fetch(url)
.then(httpresponse => httpresponse.json())
.then(parsedData => {
// 图表配置:pe_ttm
var params = {};
params.chartid='pe_ttm';
codeName=convertIndexCode("<?=$_REQUEST['code'] ?>");
params.legend = [codeName,'pe_ttm'];
params.text = params.legend[0]+' V.S '+params.legend[1];
params.data1 = pickData(parsedData, 'trade_date', 'close');
params.data2 = pickData(parsedData, 'trade_date', 'pe_ttm')
dataCal = calculateStats(params.data1);
params.sub_text = "TTM PE Max:"+dataCal['max'];
params.sub_text += " Min:"+dataCal['min'];
params.sub_text += " Average:"+dataCal['avg'];
params.sub_text += " Recent:"+dataCal['last'];
doubleLineChart(params);
// 图表配置:pb
params = {};
params.chartid='pb';
codeName=convertIndexCode("<?=$_REQUEST['code'] ?>");
params.legend = [codeName,'pb'];
params.text = params.legend[0]+' V.S '+params.legend[1];
params.data1 = pickData(parsedData, 'trade_date', 'close');
params.data2 = pickData(parsedData, 'trade_date', 'pb')
dataCal = calculateStats(params.data1);
params.sub_text = "TTM PE Max:"+dataCal['max'];
params.sub_text += " Min:"+dataCal['min'];
params.sub_text += " Average:"+dataCal['avg'];
params.sub_text += " Recent:"+dataCal['last'];
doubleLineChart(params);
// 图表配置:total_mv
params = {};
params.chartid='total_mv';
codeName=convertIndexCode("<?=$_REQUEST['code'] ?>");
params.legend = [codeName,'总市值-万亿'];
params.text = params.legend[0]+' V.S '+params.legend[1];
params.data1 = pickData(parsedData, 'trade_date', 'close');
params.data2 = pickData(parsedData, 'trade_date', 'total_mv')
params.data2 = params.data2.map(item => {
return {
value: [
item.value[0],
parseFloat((parseFloat(item.value[1]) / 10000 / 10000 / 10000).toFixed(2))
]
};
});
dataCal = calculateStats(params.data1);
params.sub_text = "TTM PE Max:"+dataCal['max'];
params.sub_text += " Min:"+dataCal['min'];
params.sub_text += " Average:"+dataCal['avg'];
params.sub_text += " Recent:"+dataCal['last'];
doubleLineChart(params);
})
.catch(error => console.error('数据加载失败:', error));
// 窗口大小自适应
window.addEventListener('resize', () => {
[pe_ttm, pb, total_mv].forEach(chart => chart.resize());
});
function doubleLineChart(params){
/*
需要外部提供:
chartid: div container id
legend: array
unit: str
sub_text: str
data:data1,data2, array
*/
var dom = document.getElementById(params.chartid);
var myChart = echarts.init(dom,'dark');
option = null;
option = {
title: {
text: params.text,
subtext: params.sub_text,
textAlign:'center',
left:'50%'
},
tooltip: {
trigger: 'axis'
},
legend: {
data:params.legend,
right:'20'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'time',
boundaryGap: false
},
yAxis: [{
type: 'value',
name:params.legend[0], //图列
show:true
},
{
type:'value',
name:params.legend[1], //图例
//scale:true,
boundaryGap:false,
show:true,
splitLine:{
show:false, //Y2 坐标刻度横线
},
}
],
dataZoom: [{
type: 'inside', //or slider
start: 0,
end: 100
}, {
start: 0,
end: 100,
handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
handleSize: '80%',
handleStyle: {
color: '#fff',
shadowBlur: 3,
shadowColor: 'rgba(0, 0, 0, 0.6)',
shadowOffsetX: 2,
shadowOffsetY: 2
}
}],
series: [
{
name:params.legend[0],
type:'line',
yAxisIndex:0,
symbol:'none',
data:params.data1
},
{
name:params.legend[1],
type:'line',
yAxisIndex:1,
symbol:'none', //数据圆点
smooth:false,
data:params.data2
}
]
};
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
}
</script>
<?php include_once "html/footer.php"; ?>
+101
View File
@@ -1,3 +1,11 @@
/*
* @Author: 杨水淼 yangshuimiao@jsjd.cc
* @Date: 2025-03-21 11:58:51
* @LastEditors: 杨水淼 yangshuimiao@jsjd.cc
* @LastEditTime: 2025-07-08 14:47:38
* @FilePath: \echarts\js\pubfunc.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
/**
* hide switch the iframe
* @param cbid:checkbox id
@@ -33,3 +41,96 @@ function getRows(jsonData,array){
return listSplit;
}
function dmChange(parid,dayblock,monblock){
var v= $('#'+parid).val();
if(v=='Monthly'){
$('#'+dayblock).css('display','none');
$('#'+monblock).css('display','inline');
}
if(v=='Daily'){
$('#'+dayblock).css('display','inline');
$('#'+monblock).css('display','none');
}
}
/*
<option value='000001.SH'>上证指数</option>
<option value='399001.SZ'>深圳成指</option>
<option value='399005.SZ'>中小板指</option>
<option value='399006.SZ'>创业板指</option>
<option value='000016.SZ'>上证50</option>
<option value='399300.SZ'>沪深300</option>
<option value='399905.SZ'>中证500</option>
*/
function convertIndexCode(tscode){
switch(tscode){
case '000001.SH':
return '上证指数';
case '399001.SZ':
return '深圳成指';
case '399005.SZ':
return '中小板指';
case '399006.SZ':
return '创业板指';
case '000016.SZ':
return '上证50';
case '399300.SZ':
return '沪深300';
case '399905.SZ':
return '中证500';
default:
return '';
}
}
function formatDateToYYYYMMDD(dateStr) {
return dateStr.replace(/-/g, '');
}
function pickData(data, dateKey, valueKey) {
return data.map(item => ({
value: [
item[dateKey].slice(0, 4) + '-' + item[dateKey].slice(4, 6) + '-' + item[dateKey].slice(6, 8), // 格式化日期 yyyymmdd 转为 yyyy-mm-dd
item[valueKey].toFixed(2) // 保留两位小数
]
}));
}
/* 将上述pickData函数返回的结果,value计算返回最大值,最小值,均值,以及最后一个值 */
function calculateStats(data) {
if (data.length === 0) {
return {
max: null,
min: null,
avg: null,
last: null
};
}
let max = -Infinity;
let min = Infinity;
let sum = 0;
let last = null;
for (const item of data) {
const value = parseFloat(item.value[1]); // 提取 value 数组中的第二个元素(数值部分)
if (value > max) {
max = value;
}
if (value < min) {
min = value;
}
sum += value;
last = value; // 更新最后一个值
}
const avg = sum / data.length;
return {
max: max.toFixed(2),
min: min.toFixed(2),
avg: avg.toFixed(2),
last: last.toFixed(2)
};
}
+97
View File
@@ -0,0 +1,97 @@
function doubleLineChart(){
/*
需要外部提供:
chartid: div container id
legend: array
unit: str
sub_text: str
data:data1,data2, array
*/
var dom = document.getElementById("chartid");
var myChart = echarts.init(dom,'dark');
option = null;
option = {
title: {
text: legend[0]+' V.S '+legend[2],
subtext: subtxt,
textAlign:'center',
left:'50%'
},
tooltip: {
trigger: 'axis'
},
legend: {
data:legend,
right:'20'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'time',
boundaryGap: false
},
yAxis: [{
type: 'value',
name:legend[0], //图列
show:true
},
{
type:'value',
name:legend[2]+unit, //图例
//scale:true,
boundaryGap:false,
show:true,
splitLine:{
show:false, //Y2 坐标刻度横线
},
}
],
dataZoom: [{
type: 'inside', //or slider
start: 0,
end: 100
}, {
start: 0,
end: 100,
handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
handleSize: '80%',
handleStyle: {
color: '#fff',
shadowBlur: 3,
shadowColor: 'rgba(0, 0, 0, 0.6)',
shadowOffsetX: 2,
shadowOffsetY: 2
}
}],
series: [
{
name:legend[0],
type:'line',
yAxisIndex:0,
symbol:'none',
data:data1
},
{
name:legend[2],
type:'line',
yAxisIndex:1,
symbol:'none', //数据圆点
smooth:false,
data:data2
}
]
};
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
}