vtkChartXY is rendered only in VtkRemoteView

I’m trying to make a 2d plot to run in the browser, but it gets rendered only in VtkRemoteView mode
in VtkLocalView it shows just white blank screen and prints
Gtk-Message: 03:45:36.722: Not loading module “atk-bridge”: The functionality is provided by GTK natively. Please try to not load it.

    colors = vtkNamedColors()

    renwin = vtkRenderWindow()
    renwin.SetWindowName('MultiplePlots')
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)
    iren.GetInteractorStyle().SetCurrentStyleToTrackballCamera()


 
    # Link the renderers to the viewports.
    left_renderer = vtkRenderer()
    left_renderer.SetBackground(colors.GetColor3d('AliceBlue'))
    renwin.AddRenderer(left_renderer)


    # Create the charts.
    left_chart = vtkChartXY()
    left_chart_scene = vtkContextScene()
    left_chart_actor = vtkContextActor()

    left_chart_scene.AddItem(left_chart)
    left_chart_actor.SetScene(left_chart_scene)

    left_renderer.AddActor(left_chart_actor)
    left_chart_scene.SetRenderer(left_renderer)

    x_axis = left_chart.GetAxis(vtkAxis.BOTTOM)
    x_axis.GetGridPen().SetColor(colors.GetColor4ub("LightGrey"))
    x_axis.SetTitle('x')
    y_axis = left_chart.GetAxis(vtkAxis.LEFT)
    y_axis.GetGridPen().SetColor(colors.GetColor4ub("LightGrey"))
    y_axis.SetTitle('cos(x)')
    left_chart.GetBackgroundBrush().SetColorF(*colors.GetColor4d('MistyRose'))
    left_chart.GetBackgroundBrush().SetOpacityF(0.4)
    left_chart.SetTitle('Cosine')



    server = get_server(client_type = "vue2")
    ctrl = server.controller

    with SinglePageLayout(server) as layout:
        layout.title.set_text("Hello trameee")

        with layout.content:
            with vuetify.VContainer(
                fluid=True,
                classes="pa-0 fill-height",
            ):
                view = vtk.VtkRemoteView(renwin)
    server.start()
    

VtkLocalView use vtk.js which does not implement charting rendering. If you want charts, you can use plotly in python and leverage trame to display them in a web interface. Either way the code run on the server, not in the browser, but it is display in the browser.

HTH,

Seb

1 Like

Thanks a lot Sebastien