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

How to set bubble marker on all bars in bar chart #2297

Closed
vladimirkovacevic opened this issue Feb 22, 2024 · 3 comments
Closed

How to set bubble marker on all bars in bar chart #2297

vladimirkovacevic opened this issue Feb 22, 2024 · 3 comments

Comments

@vladimirkovacevic
Copy link

I want to create bar chart visualisation that will have value indicators over every bar in bar chart.


bar = Bar().add_xaxis(ds)
    for yxais in scores:
        bar.add_yaxis(*yxais)
        bar.set_global_opts(title_opts=opts.TitleOpts(title=f'Retention percentage'))
        bar.set_series_opts(
            label_opts=opts.LabelOpts(is_show=False),
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="max", name="", symbol_size=54),
                    opts.MarkPointItem(type_="min", name="", symbol_size=54),
                    opts.MarkPointItem(type_="average", name="", symbol_size=54),
                ]
            ),
        )
        bar.render(metric + ".html")

But, MarkPointItem requires setting "type_" which must be some of max, min or average, but that leaves some of the bars without value above them. How can I set value above every bar in barplot?

@sunhailin-Leo
Copy link
Member

@vladimirkovacevic

  • Try this code
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker


xAxis = Faker.choose()
yAxis = Faker.values()
mark_point_datas = []

for i in range(len(xAxis)):
    mark_point_datas.append(opts.MarkPointItem(name=f"{i}", coord=[i, yAxis[i]], value=yAxis[i]))


c = (
    Bar()
    .add_xaxis(xAxis)
    .add_yaxis("商家A", yAxis)
    .set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))
    .set_series_opts(markpoint_opts=opts.MarkPointOpts(data=mark_point_datas))
    .render("issue_2297.html")
)

image

@vladimirkovacevic
Copy link
Author

@sunhailin-Leo thank you for detailed response. One more thing, if I have a grouping like in this attached image
bar
how can I set coord parameter in MarkPointItem object?

@sunhailin-Leo
Copy link
Member

@vladimirkovacevic

  • You can try this: add_yaxis("商家A", yAxis, markpoint_opts=opts.MarkPointOpts(data=mark_point_datas)) instead of ``set_series_opts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants