The Road to ChartEx Support

In 2022, with time on my hands and some background in office document processing, I started volunteering as a code contributor to the LibreOffice project. Seeing much to be done on chart handling, and few doing it, I jumped into the chart code, fixing some bugs and implementing the pie-of-pie and bar-of-pie chart types.

Bar-of-pie chart, as rendered by Collabora Office.

Charts as a day job

subsequently took a position with Collabora, where I have continued to work primarily on charts. (There’s still a lot to be done!) A customer had requested that the company improve support for some new chart types, so that has been my focus, and has continued until now even long after the customer was satisfied.

What ChartEx is

The new types, defined in the ChartEx namespace, are ones introduced by Microsoft with its Office 2016 release, and include charts like funnel, pareto-line, and sunburst. The first task was to support reading, storing, and writing the charts, so that a document created in Microsoft Office could be opened and re-saved in Collabora Office without losing the chart content—even though it wouldn’t be visible (yet) in Collabora Office. This was a significant lift, but is now mostly complete, so your chart content is now preserved through a trip through Collabora Office.

A note on credit

Italo Vignoli wrote extensively about this work in a recent blog post from The Document Foundation, LibreOffice’s charitable parent organisation. On a technical level, Vignoli’s post is mostly accurate, and it’s a detailed look at the challenges in keeping up with a changing ‘open’ specification (XLSX) and the problems inherent in a format controlled by a single dominant, private organisation (Microsoft). And it was gratifying to see this work celebrated publicly. However, it was surprising, and a bit disheartening, that Vignoli did not in any fashion acknowledge me or my employer, Collabora, which has funded the work. In fact, he studiously avoided any mention of just how this extensive support appeared in the LibreOffice code base. “LibreOffice 26.8 adds basic support for importing and exporting a range of chart types…”, he writes, in a sentence devoid of actors, authors, funders, or supporters. For an organisation that rightly celebrates its development community, it was disappointing that an official blog kept its community nameless, faceless, and unacknowledged. That is particularly so since some of the more recent work was taken from Collabora Office and cherry picked across to LibreOffice by a TDF staffer.

Parsing the new namespace

But back to the interesting part, which is the chart support. From a technical standpoint, the changes required were extensive but not particularly difficult. The content for the new chart types is described in the ChartEx schema linked above, which, as Vignoli notes, is not part of the ISO/IEC 29500 standard for Office Open XML. To parse ChartEx, the parser must accept the new namespace and handle the content in the schema. Some OOXML readers employ parser generators as a preliminary step to create the parse code directly from the schema, with the generated code sitting atop a SAX parser. Hooks are then manually placed at strategic locations in the parse code to call into the main system, delivering a tag’s worth of data at a time for certain tags. Collabora Office/LibreOffice has historically taken a more hand-crafted approach, with implementation manually coded for supported tags and attributes. That same pattern was followed here.

Into the ChartModel

The parsed data then goes into an instance of ChartModel, a class derived from the XChartDocument abstract class defined in the UNO interface. The UNO interface is designed to be highly flexible, with much of the data expressed in simple, unconstrained types like integers or strings as opposed to enumerated values, for instance. This makes it somewhat difficult and error-prone to work with, but the benefit can be seen here, where no changes to the UNO API have been required to implement eight new chart types (though some new lower-level content is not accessible via the API).

Export back to OOXML

Export back to OOXML also follows established patterns. In many cases chartex structures are very similar to corresponding structures for older chart types, with a new “cx” namespace abbreviation replacing the older “c” abbreviation. In those cases, we were able to repurpose existing export functionality with minor changes. In other cases, entirely new export functions were necessary.

What about ODF?

So far, none of the import/export support exists for ODF. That will require changes to the ODF schema, analogous to those Microsoft added to the OOXML specification. It will be important to add support for ODF, as the only truly open office document format. But since Collabora Office/LibreOffice can’t yet natively create most of the new chart types, implementing ODF import/export is a lower priority.

Success with rendering and what's next

You can now render funnel charts in Collabora Office. Try it for yourself with a nightly build.

So the next, and maybe more exciting, step is to support creating, viewing, and editing the ChartEx types in Collabora Office. This will be a longer task, but we’re on our way. Rendering support for funnel charts is in, and you can learn how to access nightly builds of Collabora Office here(https://www.collaboraonline.com/blog/flatpak-repository-for-collabora-office-desktop-nightly-builds/ ) to try it out and download a test funnel chart file here (https://share.collabora.com/index.php/s/pcNfdjEEc3964mS ) (password: chartex-test-doc). Full support for display and editing of other ChartEx types will come in the future.