Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

面积图绘制偶尔出现直线 #3024

Closed
caicaishmily opened this issue Nov 19, 2020 · 1 comment
Closed

面积图绘制偶尔出现直线 #3024

caicaishmily opened this issue Nov 19, 2020 · 1 comment
Labels

Comments

@caicaishmily
Copy link

caicaishmily commented Nov 19, 2020

  • G2 Version: 4.0.15
  • Platform: Mac

正常的图表

image

页面上有一些时间间隔切换的交互然后根据选中的时间间隔去请求 API 但是偶尔图表绘制的时候就会出现以下情况:

image

image

我请求回来的数据是这样的:

[{"date":1605789000000,"high":"14961.06","low":"14945.55","open":"14949.07","close":"14957.26","vol":"239430.4543178","rece":"14957.26","price":"14957.26"}, ......]

我的代码:

import React, { useEffect, useState } from 'react'
import { Chart } from '@antv/g2'
import dayjs from 'dayjs'

export default function KLine ({posCoinDetail, defaultTime}) {
  const [loading, setLoading] = useState(false)

  useEffect(() => {
    setLoading(true)
    let dom = document.getElementById('kline-container')
    dom.innerHTML = null
    fetch(`API_URL`)
    .then(res => res.json())
    .then(r => {
      setLoading(false)
      const chart = new Chart({
        container: 'kline-container',
        autoFit: true,
        height: 380,
        padding: [50, 20, 25, 0]
      });

      let data = r.data.reverse()

      chart.changeData(data);
      
      chart.tooltip({
        showCrosshairs: true, // 展示 Tooltip 辅助线
        showMarkers: false,
        shared: true,
        showTitle: false,
        itemTpl: "<li><span style='line-height: 16px; font-size: 16px; display: inline-block; margin-bottom: 10px;'>{price}</span><br/><span>{date}</span></li>",
        domStyles: {
          'g2-tooltip': {
            background: "rgba(0, 0, 0, 0.705064)",
            borderRadius: 4,
            color: "#fff"
          },
          'g2-tooltip-list-item': {
            fontSize: "20px"
          }
        }
      });
  
      chart.legend({
        position: 'top'
      })
  
      chart.axis(false)
      
      chart.line().position('date*price').color("#225cff").tooltip('date*price', (date, price) => {
        return {
          date: dayjs(date).format('MMM DD, YYYY'),
          price: `€${Number(price).toFixed(2)}`
        }
      })

      chart.area().position('date*price').color("l(90) .1:#225cff 1:#fff")
      
      chart.render();
    })
    
  }, [defaultTime, posCoinDetail])

  const Loading = () => (
    <div className='loading'>
      <img 
        src={loading_gif} 
        alt="loading"
      />
    </div>
  )

  return (
    <div>
      {loading && <Loading/>}
      <div id="kline-container"></div>
    </div>
  )
}
@hustcc
Copy link
Member

hustcc commented Jan 29, 2021

要看具体出现直线之后的,数据是什么样的~ 是否可以贴一下完整的可复现的代码,或者 live demo,方便我来调试和修复。

@hustcc hustcc added the Mark label Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants