Written by

Integration Engineer at Cognosante
Question Oliver Wilms · Sep 8

Plotly Bar Graph is NOT showing expected values

I am trying to add Plotly Bar graph in a div to a CSPpage. I am working in IRIS 2022.1. I created persistent class.

I copied relevant code into github repo:

oliverwilms/iris-python-plotly
 

iris-python-plotly/csp/otwPlotly.csp at master · oliverwilms/iris-python-plotly
 

Set tPlotlyDiv = ##class(dc.python.test).PlotlyDiv(trnYear,trnMonth)

ClassMethod PlotlyDiv(pTrnYear = 2025, pTrnMonth = 8) As %String
{
    Set importlib = ##class(%SYS.Python).Import("importlib")
    Set plotdiv = ##class(%SYS.Python).Import("plotdiv")
    Do importlib.reload(plotdiv)
    Set div = plotdiv.gendiv(pTrnYear,pTrnMonth)
    Return div
}

iris-python-plotly/python/plotly.py at master · oliverwilms/iris-python-plotly
 

Product version: IRIS 2022.1

Comments

Oliver Wilms · Sep 8

This line in plotly.py generates a dataframe:

df = iris.sql.exec(query).dataframe()

where query = "SELECT Top 10 Category, Credit, Debit, TrnCount FROM dc_iris.trncount where TrnYear=2025 and TrnMonth=8 Order By Debit DESC"

The bars in the graph reflect rows 0 to 9, not the amount in 'Debit'

0
Dmitrij Vladimirov · Sep 12

Here is your Plotly code.
 

fig = go.Figure(
       data=[
           go.Bar(
               y=df['category'],
               x=df['debit']
           )
       ],
       layout=go.Layout(
           title='Total Monthly Cost'
       )
    )


You should convert df to a list to pass the data to the graph. Since it takes an array, it cannot display a data frame.
Try it like this:
df['category'].tolist()

df['debit'].tolist()

0
Oliver Wilms  Sep 12 to Dmitrij Vladimirov

It works. Thank you, Dmitrij

0