任何人都可以帮助我,如何通过使用破折号和Python单击高图图的任意点来获取悬停数据。下面给出了用于绘制高图表条形图的代码和数据集。 在此输入图像描述。
代码
import pandas as pd
import dash_alternative_viz as dav
import dash
from dash import html
df = pd.read_csv("bar.csv")
bar_plot_dict = {
"series": [],
"title": {"text": "Bar Plot"},
"xAxis": {"categories": df["sectors"]},
"chart": {"type": "bar", "inverted": True, "height": "900px"},
}
for col, color in zip(
[i for i in df.columns if i.startswith("col")],
["green", "red", "yellow"],
):
series = {
"name": col,
"data": df[col],
"color": color,
"type": "bar",
"stacking": "normal",
}
bar_plot_dict["series"].append(series)
app = dash.Dash(__name__)
highchart_barplot = html.Div(dav.HighChart(id="line-plot", options=bar_plot_dict))
app.layout = html.Div([highchart_barplot])
app.run(port=8003, debug=True)
数据集
,扇区,第 1 列,第 2 列,第 3 列
0,A,4.89555774,15.20538823,235.1483496
1,B,330.7514786,14.43483274,120.3015848
2,C,323.2680204,35.14712088,511.8969181
要使用 Dash 在 Highcharts 中获取悬停 clickData,请使用 dcc.Graph 组件和 Highcharts 中的图形,并通过 Dash 回调中的hoverData 属性访问悬停数据。