How to create varieties of charts

Plotting charts using plotly in anvil is quite different from using pure plotly in Jupiter notebook.
The plots I have been able to create are the sample you used during trainings. Creating line plots and bar charts is easy following the steps provided in examples.
How do I go about creating column charts and pie charts. This are useful charts in data visualizations.

Hello, from what I understand from other posts on the forum, not all Plotly modules are available inside of Anvil at the moment. Once Anvil updates to a newer Plotly, you should have more options.

Having said that, I’m not sure if pie charts are available or not at this point (I don’t often use Plotly). Have you tried making a pie chart (based on Plotly docs) and gotten an error? If so let us know.

1 Like

Yes I’ve tried creating charts base on plots docs but it gives errors.

Please what python libraries do you use to create charts in anvil.
Is matplotlib working fine if yes. How do I create an histogram and pie chart in anvil using maplotlib?

Hi @peterlimited2000,

Here are a couple of examples using Plotly. I’ve created a histogram and pie chart based on the examples in the Plotly docs.

https://anvil.works/build#clone:GNHAJLMYDFYOKFEG=WP37I4GDOM2WNBQQU3LA5JIW

Hope this helps you to get started :slight_smile:

2 Likes

Yeah it helped but still histogram is still not working.maybe because I’ve not upgraded my account.

With a free plan you will need to use basic Python and not use numpy.

You can get it to work by using this code:

import anvil.server
import random
  
@anvil.server.callable
def get_histogram_data():
  return [random.gauss(1, 1) for _ in range(500)]

And this settings:
image

1 Like

Thanks a lot but histogram is still frustrating me.

Capture Captures

The screenshots above is the result I want. but cant still create it with the codes below.

Hi there. It looks like there is a syntax error after the second optional argument where you are defining your histogram. Plotly docs seem to indicate that “histfunc” should be a single string. Perhaps try “sum” or “count”. The error itself is telling you that you have specified a positional argument ("sum") that follows a keyword argument (histfunc="count"), and that is not valid Python syntax.

If this is not the issue that you had in mind, please clarify and paste your reproducible code directly (rather than a screenshot). This makes it easier to provide assistance.

A post was split to a new topic: Error in plotting