Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Nikpapi
Partner - Contributor
Partner - Contributor

Using enigma.js to create a chart instantly

Hello, 
I have been working on integrating an Angular application with Qlik Sense. The objective is to establish a connection, create an application, set up the script, reload the data, and build a sheet containing a chart.
However, I have encountered an issue with chart creation.
The chart is being created, but it doesn't appear within the designated sheet.
I have used enigma.js. and below is the code snippet I have utilized to generate the sheet and the pie chart:

 

async function createNewAppAndLoadData(global: any, newAppName: string): Promise<any> {
  // Create a new app
  const newApp = await global.createApp({ qAppName: newAppName });
  // Open the newly created app to get the full app object
  const openedApp = await global.openDoc(newApp.qAppId);
  console.log('Opened app:', openedApp);

  const scriptContent = `
    TempTable:
    Load
      RecNo() as ID,
      Rand() as Value
    AutoGenerate 100;
  `;

  // Set the script of the opened app
  await openedApp.setScript(scriptContent);
  console.log('Script set on the opened app');
  
  // Reload the opened app
  await openedApp.doReload();
  console.log('Reload complete for the opened app');

  const newSheet = await openedApp.createObject({
    qInfo: {
      qType: 'sheet',
    },
    qMetaDef: {
      title: 'My new sheet created',
    },
    
    
  });
  console.log('New sheet created:', newSheet);
  const sheetId = newSheet.id
  console.log('New sheet created:', sheetId);
 
 const chartDef = {
    "qInfo": {
        "qType": "piechart"
    },
    "qHyperCubeDef": {
        "qDimensions": [
            {
                "qDef": {
                    "qFieldDefs": ["ID"],
                    "qSortCriterias": [
                    ]
                },
            }
        ],
        "qMeasures": [
            {
                "qDef":{
                    "qDef": "=Sum(Value)"
                }
            }
        ],
        "qInitialDataFetch": [
            {
                "qLeft": 0,
                "qWidth": 10,
                "qTop": 0,
                "qHeight": 100
            }
        ]
    }
  };

  const chartHandle = await openedApp.createSessionObject(chartDef);
  console.log(chartHandle);
  const chartLayout = await chartHandle.getLayout(); 
  console.log(chartLayout);

  await openedApp.doSave();
  console.log('App saved');
  return openedApp;
  
}
 

 

Can somebody help me?. 😀

 

Labels (1)
2 Replies
Skage
Partner - Creator
Partner - Creator

Hi!

Did you find a solution?

Curious about how, in that case.

/lars

 

Nikpapi
Partner - Contributor
Partner - Contributor
Author

@Skage unfortunately no. We've used another approach for this issue.