我正在使用React呈现一个股票/烛台图表,但问题是当我将光标悬停在数据点上时,会生成工具提示,但图表会被销毁。
如果我将chart.tooltip().positionMode('float');更改为chart.tooltip().positionMode('point');,工具提示根本不会呈现,但图表仍然存在。
我尝试了各种不同的position()选项,也尝试了anchor(),但似乎都没有对工具提示产生任何影响。
请在此处查看完整的代码https://gitlab.com/gsrnt/react-cc-tracker.git
这是图表的完整js页面。
import AnyChart from 'anychart-react'
import anychart from 'anychart'
export default class Chart extends Component {
render() {
var coinId = this.props.location.state.coinId.id
var coinName = this.props.location.state.coinName.name
//set type of chart
var chart = anychart.stock();
//if posistion mode is 'float', chart disappears
//if position mode is 'point', tooltip doesn't render
chart.tooltip().positionMode('float');
//chart background color
chart.background().fill("#282c34");
// load jsonfile + function
anychart.data.loadJsonFile("https://api.coingecko.com/api/v3/coins/" + coinId + "/ohlc?vs_currency=usd&days=max",
function (data) {
// create a data table
var dataTable = anychart.data.table(0, 'MMM d, yyyy');
dataTable.addData(data);
// map data
var mapping = dataTable.mapAs({ 'open': 1, 'high': 2, 'low': 3, 'close': 4 });
// set the series
var series = chart.plot(0).candlestick(mapping);
// set the series name
series.name(coinName + " Price Data");
// set the chart title
chart.title(coinName + " Price Data");
// create a plot
var plot = chart.plot(0);
// create an EMA(Exponential Moving Average) indicator with period 20
var ema20 = plot.ema(mapping, 20).series();
// set the EMA color
ema20.stroke('1, white');
// disable the scroller axis
chart.scroller().xAxis(false);
// map "open" values for the scroller
var openValue = dataTable.mapAs();
openValue.addField('value', 2);
// create a scroller series with the mapped data
chart.scroller().column(openValue);
})
chart.tooltip().anchor("bottomLeft");
return <AnyChart
width={'100%'}
height={900}
instance={chart}
/>;
}
}发布于 2021-09-24 06:12:48
AnyStock仅支持工具提示的浮动位置模式。因此,您可以简单地删除该行。
https://stackoverflow.com/questions/69272913
复制相似问题