I have done it with a tuple because each year will match with different 18 values for my 18 cities.
the first part of your code will display on my dropdown the years correctly! thanks!
But do the app knows which year corresponds to each value correctly? without doing it with a tuple?
Like my chart code is this:
def build_revenue_graph(self):
db_data = anvil.server.call('get_iap')
self.plot_1.data = go.Bar(x = [x['Cidade'] for x in db_data],
y = [x['IAP'] for x in db_data],
marker=dict(color='#2196f3'))
self.plot_1.layout.title = "ĂNDICE ARROWPLUS"
So x axis displays my cities and y axis displays my IAP values.
How can i change this so the chart change values accordingly to the chosen year on the dropdown?
You could filter the data for the selected year. One way to do this would be to add the currently selected year as a parameter to your âget_iapâ server function, and in that function, filter the rows you retrieve from the data table.
An alternative would be to retrieve all of the data and build a dictionary of tuples, keyed by year.
You cannot select the year from within a server function, you would have to pass that in as a parameter.
Scrap my previous suggestion. You could add a filter to your list comprehensions to restrict the plot data to whatever year is selected in the drop down.
@tiago.mendes Please see these guidelines on asking a good question:
Asking âhow do I do X?â without showing what youâve tried is not a great approach on the forum.
As a general suggestion since you are just getting started, you may want to go through the introductory tutorials as they will demonstrate how to pass parameters to a server function, among many other common things (dealing with events, etc). In addition, you may want to Google how to filter a list and/or tuple since that may be one viable approach here.
Feel free to post back here when you can show what youâve tried with some small code examples. This will help others to jump in and help more easily.
@alcampopiano i know that, the question i asked in this post i posted code, i wrote what i did and i even added 2 screenshots! After that is just comments of people trying to help me and i reply back most of the times with code, its not a new question, we are discussing the same question i posted before correctlyâŚ
I just need to get that correclty and the question is answered!
@ahawes so, i know that to implement something like that i need to get the dropdown selected value like this
` year = self.start_year.selected_value`
My code for the chart is this:
def build_revenue_graph(self):
db_data = anvil.server.call('get_iap')
self.plot_1.data = go.Bar(x = [x['Cidade'] for x in db_data],
y = [x['IAP'] for x in db_data],
marker=dict(color='#2196f3'))
self.plot_1.layout.title = "ĂNDICE ARROWPLUS"
What i need is to know how to filter the chart values by the year i select⌠in terms of code i dont know how to do thatâŚ
In the search parameters i have to pass my year varialble which is the selected alue from the dropdown but i dont know how to pass that variable which is on client side code to server module function.
Or can i do it all on client side? and if i can, what can i change on my code?
def build_iap_graph(self):
year = self.start_year.selected_value
db_data = anvil.server.call('get_iap')
self.plot_1.data = go.Bar(x = [x['Cidade'] for x in db_data],
y = [x['IAP'] for x in db_data],
marker=dict(color='#2196f3'))
self.plot_1.layout.title = "ĂNDICE ARROWPLUS"
def build_iap_graph(self):
year = self.start_year.selected_value
db_data = anvil.server.call('get_iap')
self.plot_1.data = go.Bar(x = [x['Cidade'] for x in db_data if x['Ano'] == year],
y = [x['IAP'] for x in db_data if x['Ano'] == year],
marker=dict(color='#2196f3'))
self.plot_1.layout.title = "ĂNDICE ARROWPLUS"
but it only displays the first value on the dropdown when i run the app(which is the year 2011), do i need to do something else to display the other years when selected?
My dropdown code is this: self.start_year.items = set(row['Ano'] for row in app_tables.iap_table.search())
It looks like youâve got mixed up with what code calls other code. You wouldnât normally call event handlers from your custom logic. Event handlers are triggered by user interaction, timers, etc.
The change event should call your chart building function, not the other way around.
I would recommend going through the tutorials (possibly again) to get a better understanding.
@ahawes Thank you for your help, i am almost at the solution!
I did read the tutorials but the examples they give are different than what i need you know? so i just need a little bit more help and i will be done
So, as you said, the change event should call my chart building function like this right?
def start_year_change(self, **event_args):
year = self.start_year.selected_value
self.build_iap_graph()
and now i dont use the âyearâ variable on the chart building function since its here, and i get this error:
NameError: name âyearâ is not defined
In the init functions i deleted the one that builds the chart and added this one, the start_year_change function, is this correct?
If you need more information i post here my app so you can clone:
You are getting the NameError because the year variable only exists locally within the start_year_change event. Try adding a year parameter to your build_iap_graph function and then pass that in when you call it.