Skip to Content
Author's profile photo Former Member

SAP Lumira – vizPacker extension message – Failed to create chart: TypeError: Cannot read property ‘0’ of undefined

This issue was fixed in SAP Lumira 1.15 so these steps are no longer needed.

Just a quick post before I go for my vacation in case you also run into this known issue/message when using your extension inside SAP Lumira 1.14.

The issue

I was using the sample code that gets generated by the vizPacker, the only thing I had changed was the extension ID and plot area ID like we did with the Hello World extension for SAP Lumira.

The extension worked fine inside of the vizPacker preview and externally in Google Chrome:

It works in vizPacker preview.png

But when I installed my extension into SAP Lumira and then switched to it the following message was displayed:

Failed to create chart: TypeError: Cannot read property ‘0’ of undefined

Cannot read property '0' of undefined.png

What caused it?

The generated render code call to _util.toFlattenTable throws an exception when SAP Lumira does not pass in any data to display.

We avoided this issue with Hello World extension because we replaced all of the render code with our own.

These are the steps I went through to find out what was wrong:

  1. I closed down SAP Lumira
  2. Then I followed the SAP Lumira SDK Getting Started Guide instructions to enable debug mode
  3. I then started SAP Lumira and went into debug mode (again referring to the guide) so I could add a break point to the top of my render function
  4. I then switched to my extension which stopped at the breakpoint so I could step through and see what was wrong
  5. As I stepped through the code I saw the error was coming from inside the generated code:
    var fdata = _util.toFlattenTable(data);

The workaround

You apply this workaround every time the render function is generated by the vizPacker.

You can workaround the issues in the generated render code to:

  1. Catch the error from var fdata = _util.toFlattenTable, suppress it, and return
    This call is commonly used to turn the SAP Lumira cross table data format into a simple JSON array we can work with in our extension
  2. Fix the sample chart code to return when dimensions are passed in but no measures

Here marked in red are the changes I made to the render code:

patched render code.png

I then packed the extension, copied it into SAP Lumira, restarted SAP Lumira, imported the vizPacker sample CSV file and then tested again and this time it worked:

It works.png

The SAP Lumira development team is fixing this issue (which may differ to the way I applied my workaround) and it should be part of the next SAP Lumira update in 2014.

Happy coding and Happy Holidays everybody!

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Tammy Powlas
      Tammy Powlas

      Enjoy your vacation, Matt!

      When you return, please consider moving this to the Lumira space so it can be more easily found.

      Thank you for sharing.

      Author's profile photo Former Member
      Former Member

      Awesome Matt, thanks for sharing your workaround. I encountered a similar problem but then i realized that you have to manage your feeds. if you define your feed as 1 to 2 measures, it will not try to render when theres 0 measures.

      Author's profile photo Former Member
      Former Member

      to be precise, please check this line

                  var ds1 = {

                      "id": "viz.ext.module.HelloWorldModule.DS1",

                      "name": "Entity",

                      "type": "Dimension",

                      "min": 0,

                      "max": 2,

                      "aaIndex": 1

      min:0 means it will still try to render even when theres no dimension, which will cause the error.

      Author's profile photo Henry Banks
      Henry Banks

      This is really cool, thanks for adding this blog to our Lumira space!