Postgres json 股票数据到 Grafana Candlestick

发布于 2025-01-20 16:47:26 字数 1131 浏览 2 评论 0原文

我正在尝试使用 Grafana 中的 Candlestick 从 postgres 单元中可视化股票价格随时间、开盘价、最高价、最低价、收盘价、成交量数据的 json 格式。 在 postgres 表 timeseries 中,我有两列:ticker,它只是股票简称,jsondata,其格式如下:

{
  "c": [
    217.68,
    221.03,
    219.89
  ],
  "h": [
    222.49,
    221.5,
    220.94
  ],
  "l": [
    217.19,
    217.1402,
    218.83
  ],
  "o": [
    221.03,
    218.55,
    220
  ],
  "s": "ok",
  "t": [
    1569297600,
    1569384000,
    1569470400
  ],
  "v": [
    33463820,
    24018876,
    20730608
  ]
}

在 Grafana 中选择Candlestick 可视化我从 postgres 服务器查询:

SELECT
  now() as time,
  ticker,
  jsondata->>'t' as t,
  jsondata->>'o' as o,
  jsondata->>'h' as h,
  jsondata->>'l' as l,
  jsondata->>'c' as c
FROM
  timeseries
WHERE
  ticker = 'a'

所以我在每个单元格中都有数组,如下所示: 图片 但我无法将数组放入行或使其出现在图表中。有什么解决办法吗? 谢谢!

数据来源是这样的: https://finnhub.io/docs/api/stock-candles< /a>

I am trying to visualize stock prices with time, open, high, low, close, volume data in json, from a postgres cell using Candlestick in Grafana.
In the postgres table timeseries I have two columns: ticker which is just the stock short name and jsondata which is formatted like this:

{
  "c": [
    217.68,
    221.03,
    219.89
  ],
  "h": [
    222.49,
    221.5,
    220.94
  ],
  "l": [
    217.19,
    217.1402,
    218.83
  ],
  "o": [
    221.03,
    218.55,
    220
  ],
  "s": "ok",
  "t": [
    1569297600,
    1569384000,
    1569470400
  ],
  "v": [
    33463820,
    24018876,
    20730608
  ]
}

In Grafana selecting the Candlestick visualization I am query this from the postgres server:

SELECT
  now() as time,
  ticker,
  jsondata->>'t' as t,
  jsondata->>'o' as o,
  jsondata->>'h' as h,
  jsondata->>'l' as l,
  jsondata->>'c' as c
FROM
  timeseries
WHERE
  ticker = 'a'

So I got arrays in each cell like this:
IMAGE
But I am not able to get the arrays into rows or make it appear in the chart. Is there any solution for this?
Thanks!

The data source is this: https://finnhub.io/docs/api/stock-candles

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

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

发布评论

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

评论(1

你的笑 2025-01-27 16:47:26

我们可以使用联合所有的分开查询

 选择
  现在()作为时间,
  股票,
  't'为json_col,
  jsondata-&gt;'t'作为json_value
  来自时间
  联盟全部
  选择
    现在()作为时间,
  股票,
  'o',
  jsondata--&gt;'o' 
  来自时间
  联盟全部
  选择
    现在()作为时间,
  股票,
  'H',
  jsondata-&gt;'h' 
  来自时间
  联盟全部
  选择
    现在()作为时间,
  股票,
  'l',
  jsondata-&gt;'l' 
  来自时间
  联盟全部
  选择
    现在()作为时间,
  股票,
  'c',
  jsondata-&gt;'c' 
  来自时间
 
 
时间|股票| JSON_COL | JSON_VALUE                          
:------------------------------------- | :----- | :------- | :-----------------------------------------------------
2022-04-12 10:43:28.011766+01 | A | T | [1569297600,1569384000,1569470400]
2022-04-12 10:43:28.011766+01 | A | O | [221.03,218.55,220]               
2022-04-12 10:43:28.011766+01 | A | H | [222.49,221.5,220.94]             
2022-04-12 10:43:28.011766+01 | A | L | [217.19,217.1402,218.83]          
2022-04-12 10:43:28.011766+01 | A | C | [217.68,221.03,219.89]            

db&lt;&gt;&gt;

We can use seperate queries joined with UNION ALL

  select
  now() as time,
  ticker,
  't' as json_col,
  jsondata->>'t' as json_value
  from   timeseries
  union all
  select
    now() as time,
  ticker,
  'o',
  jsondata->>'o' 
  from   timeseries
  union all
  select
    now() as time,
  ticker,
  'h',
  jsondata->>'h' 
  from   timeseries
  union all
  select
    now() as time,
  ticker,
  'l',
  jsondata->>'l' 
  from   timeseries
  union all
  select
    now() as time,
  ticker,
  'c',
  jsondata->>'c' 
  from   timeseries
 
time                          | ticker | json_col | json_value                          
:---------------------------- | :----- | :------- | :-----------------------------------
2022-04-12 10:43:28.011766+01 | a      | t        | [1569297600, 1569384000, 1569470400]
2022-04-12 10:43:28.011766+01 | a      | o        | [221.03, 218.55, 220]               
2022-04-12 10:43:28.011766+01 | a      | h        | [222.49, 221.5, 220.94]             
2022-04-12 10:43:28.011766+01 | a      | l        | [217.19, 217.1402, 218.83]          
2022-04-12 10:43:28.011766+01 | a      | c        | [217.68, 221.03, 219.89]            

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文