diff --git a/chart.py b/chart.py index 150b74d..4e6ab58 100644 --- a/chart.py +++ b/chart.py @@ -224,9 +224,18 @@ class QuantChart: histogram = macd_chart.create_histogram(name=macd_name) hist_data = df[["time", macd_name]].copy() - hist_data["color"] = hist_data[macd_name].apply( - lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色 - ) + hist_data['prev_value'] = hist_data[macd_name].shift(1) + # 设置颜色逻辑 + def get_histogram_color(row): + current, prev = row[macd_name], row['prev_value'] + is_hollow = (current >= 0 and current < prev) or (current < 0 and current > prev) + if current >= 0: + return "rgba(255, 0, 0, 0.3)" if is_hollow else "#ff0000" + else: + return "rgba(0, 255, 0, 0.3)" if is_hollow else "#00FF00" + hist_data["color"] = hist_data.apply(get_histogram_color, axis=1) + hist_data = hist_data.drop('prev_value', axis=1) + histogram.set(hist_data) macd_line = macd_chart.create_line(