Add vertical line to chart

What I’m trying to do:
Add a vertical line to a graph object plot client side

What I’ve tried and what’s not working:
I’ve followed the plotly graph object documentation, and gotten it to work on my local machine, but I don’t yet understand how to modify this to the client logic.

#what i’m trying to do in the client environment

Code Sample:

#Works on my local machine
x = [1,2,3,4,5]
y = [4,5,2,7,8]
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y,
                   mode='lines+markers',
                   name='Spotprices'))

fig.add_vline(x=3, line_width=3, line_dash="dash", line_color="green")

fig.show()
#What i want to work in the client
   x = [1,2,3,4,5]
   y = [4,5,2,7,8]
   self.plot_1.data = go.Scatter(x=x, y=y, mode='lines')
   self.plot_1.figure.add_vline(x=3, line_width=3, line_dash="dash", line_color="green")

Thanks in advance :slight_smile:

You could just do the whole plot complete with line in a server module, return the fig and just set your client-side plot.figure to the anvil.server.call

yeah I started doing that, and it is much easier, but every call to the server adds around 5 seconds to loading times, no matter the call.

So I increase speed 20 fold by doing operations in the client side.

Maybe I’m doing something wrong, but that is my experiense so far.

Two ways around that: 1) use uplink and process locally or 2) switch to persistent server from Business up, I think.

I just did a test, and making the same two plots takes 0.02 seconds in the client and 4.47 seconds through the server.

Thats a factor 165, and that is per call, so two calls will take 10 seconds and so on.

I tried making figures locally, but I don’t quite understand how to send them through. Is there a guide for that, or a hint on the format? It seems i can only send json and csv.

Businessplan is not really in my budget…

That should be the same for Uplink as for Server code.