How do I create 3D bar charts with multiple seriescollections, where depth of chart are next series data items ?

566 views
Skip to first unread message

busser...@gmail.com

unread,
Apr 25, 2020, 10:25:36 AM4/25/20
to openpyxl-users
When using VB for Excel I can create charts that look like this

chart.jpg


The closes I can come in Python using openpxyl is something like this where series are all lined up next to each other like this


chart3.jpg



Is there anyway to do the former in openpxyl ?



busser...@gmail.com

unread,
Apr 26, 2020, 2:41:41 PM4/26/20
to openpyxl-users
I may have found the answer, that this is not possible in openpyxl. In Excel and VB the chart type is 3D Column chart, rather than 3DBar chart. Seems that this chart type is not available to users of Openpyxl. This is disappointing. These chart types are extremely useful. Does anyone know if there are plans to add this chart type ?

Charlie Clark

unread,
Apr 27, 2020, 10:02:40 AM4/27/20
to openpyxl-users
On 26 Apr 2020, at 20:41, busser...@gmail.com wrote:

> I may have found the answer, that this is not possible in openpyxl. In
> Excel and VB the chart type is 3D Column chart, rather than 3DBar
> chart.
> Seems that this chart type is not available to users of Openpyxl. This
> is
> disappointing. These chart types are extremely useful. Does anyone
> know if
> there are plans to add this chart type ?

That's the with open source projects: things only happen if somebody
decides to do it themselves…

You can switch between bar and column types by setting the type

chart1.type = "bar"

But your question seems to relate to adding a z-index.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

busser...@gmail.com

unread,
Apr 27, 2020, 10:14:19 AM4/27/20
to openpyxl-users
Thanks Charlie, But yes - it is the z-index/z-axis that I'm interested in. I can change the chart type to get a somewhat representative chart, the 3DLineChart

chart4.jpg


But there is really no direct relationship between the peaks in each of these categories so I'd like to see just the peak values in the vertical columns like the 3D column display is capable of, as I showed in my original post. With the 3DLineChart, connecting the peaks just kind of makes things harder to see/interpret, But I've found no way to do this using openpyxl, and no other Python to Excel library even comes this close.

Probably need to look into matplotlib, but then I need to work out how to put the figures into Excel. And then, not sure there is any way to maintain connection to the underlying data.

Charlie Clark

unread,
Apr 27, 2020, 10:23:25 AM4/27/20
to openpyxl-users

On 27 Apr 2020, at 16:14, busser...@gmail.com wrote:

Thanks Charlie, But yes - it is the z-index/z-axis that I'm interested in.
I can change the chart type to get a somewhat representative chart, the
3DLineChart

[image: chart4.jpg]

But there is really no direct relationship between the peaks in each of
these categories so I'd like to see just the peak values in the vertical
columns like the 3D column display is capable of, as I showed in my
original post. With the 3DLineChart, connecting the peaks just kind of
makes things harder to see/interpret, But I've found no way to do this
using openpyxl, and no other Python to Excel library even comes this close.

Probably need to look into matplotlib, but then I need to work out how to
put the figures into Excel. And then, not sure there is any way to maintain
connection to the underlying data.

Well, for a bar chart the procedure is the same as for a line chart. I think the example doesn't set the categories for x-axis correctly but the z-axis is automatic.

But, for any of the complicated charts, you must be prepared to look at the XML of the generated charts because this stuff is not straightforward, particularly not how axes work. If someone has documented how to do it in VB, then the procedure will be similar in openpyxl, or at least involve similar object names.

busser...@gmail.com

unread,
Apr 27, 2020, 11:12:56 AM4/27/20
to openpyxl-users
Well, when I was referring to VB, I was the one that did the VB work. It was pretty much just that in VB you could chose the chart type of 3DColumn Chart, which is not an option in openpyxl. 

With respect to your statement about 

           Well, for a bar chart the procedure is the same as for a line chart.

I was original generating 3DBar charts 

chart5.jpg



All I did to get the line chart version was to change the code from

chart_pyxl = BarChart3D()
to
chart_pyxl = LineChart3D()

Everything else is the same.

What are you referring to by

      I think the example doesn't set the categories for x-axis correctly

I did make some adjustments so that the long strings I was using for the X axis printed out at an angle, if that is what you are referring to.

    chart_pyxl.x_axis.title = x_axis_title
    chart_pyxl.x_axis.txPr = RichText(bodyPr=RichTextProperties(anchor="ctr",anchorCtr="1",rot="-3600000",
                                                                spcFirstLastPara="1",vertOverflow="ellipsis",wrap="square"),
                                      p=[Paragraph(pPr=ParagraphProperties(defRPr=CharacterProperties()), 
                                                   endParaRPr=CharacterProperties())])

Thanks for your replies !

Bob

busser...@gmail.com

unread,
Apr 28, 2020, 3:37:15 PM4/28/20
to openpyxl-users
Still looking for suggestions. Anyone ? 

Charlie stated 

     but the z-axis is automatic

Is there some setting that I'm missing that is making the z-axis stay basically flat when used with BarChart3D() ? Really stumped by this.
Message has been deleted

Thiago Fernandes

unread,
Oct 13, 2021, 12:30:40 PM10/13/21
to openpyxl-users
It's quite simple. Try to use BarChart3D and change the grouping to standard.

chart_pyxl = BarChart3D()
chart_pyxl.grouping = 'standard'
Reply all
Reply to author
Forward
0 new messages