13 Replies Latest reply: Jan 13, 2014 5:55 AM by Clever Anjos RSS

    Passing data from qv to extension

      I wrote a D3 dependency relationship mapping extension to utilize the data selected in QV. My problem is passing the expression to the extension. Do you simply put the expressions in the Definition.xml and then it can be accessed using _this.Data.Rows?

      I am trying that with no luck....

       

      Definition.xml

      <?xml version="1.0" encoding="utf-8" ?>
      <ExtensionObject Label="d3Bar" PageHeight="100000" Path="d3Bar" Description="" Type="object" >
        <Dimension Label="Node Name" Initial="=Only(Capability)" TargetName="Dimension Name" />
        <Dimension Label="Node Description" Initial="=[Capability Definition]" TargetName="Dimension Name" />
        <Measurement Label="Entity Type" Initial="=[Support Type]"/>
        <Measurement Label="Target level 0" Initial=""/>
        <Measurement Label="Target level 1" Initial=""/>
        <Initiate Name="Chart.Title" value="Dependency View" />
        <Initiate Name="Caption.Text" Value="Dependency View" />
      </ExtensionObject>
      

       

      Accessing the data:

      for (var i = 0; i < _this.Data.Rows[0].length; i++) { 
        // get the row 
        var row = _this.Data.Rows[0][i];
        console.log(row);
      }
      
        • Re: Passing data from qv to extension
          Clever Anjos

          You should put your expression into object properties at design time.

          Right Click your object and set your expressions

          • Re: Re: Passing data from qv to extension

            Also the definition Dimension and Measurement dont seem to appear as they should and the qvpp file doesnt get generated, we have QV 11 SR2, is there anyway to force it to generate the qvpp file and read the definition.xml?

            • Re: Re: Passing data from qv to extension

              So it appears to be working now, when I manually add the dimensions and expressions using the desktop application. Might have to investigate later how to make it automatically retrieve the expression and dimensions using the definition.xml but for now its working.

               

               

              One more follow up question. Passing the data to the extension, how can I pass an array of data. An example would be such as passing all the models for the selected car maker and the description, so if toyota is selected, then getting [Toyota: {'Camry', 'a luxury sedan'}, {'Corolla', 'a mid-size sedan'}]

               

              is that possible?

                • Re: Passing data from qv to extension
                  Sean (Hyunku) Cho

                  So it appears to be working now, when I manually add the dimensions and expressions using the desktop application. Might have to investigate later how to make it automatically retrieve the expression and dimensions using the definition.xml but for now its working.

                  Delete the DynProperties.qvpp file.

                  If your Definition.xml had 2 Dimension and 3 Expressions, and create an extension object in the application, DynProperties.qvpp will be created when you add an object in it.

                   

                  Then you change Definition.xml by adding one more Dimension, this will not update existing extension object in your application, and DynProperties.qvpp will not get updated.  Therefore, you need to delete the extension object used in your application first, and then close the application and delete the DynProperties.qvpp (I am not 100% sure if this is a necessary step or not) , then add it back in your application.  You will have updated DynProperties.qvpp and if you check your data using firebug, you will see new dimension is available to use during data initialization.

                   

                  One more follow up question. Passing the data to the extension, how can I pass an array of data. An example would be such as passing all the models for the selected car maker and the description, so if toyota is selected, then getting [Toyota: {'Camry', 'a luxury sedan'}, {'Corolla', 'a mid-size sedan'}]

                   

                  is that possible?

                  Yes, it is possible.

                  All data from QlikView is coming in as a tabular format.

                  i.e. if your Dimension is Maker, Model, Type, Month-Year, and your expression is Sum(Sales).

                   

                  Your Definition.xml should have 3 Dimensions and 1 Measurement.  If you want to pass a color, then add a Text.

                  i.e.

                       <Dimension Label = "Maker", Initial="Maker" TargetName="Maker"/>

                        <Dimension Label = "Model", Initial="Model" TargetName="Model"/>

                        <Dimension Label = "Type", Initial="Type" TargetName="Type"/>     

                        <Measurement Label="Sales" Initial="SUM(Sales)" TargetName="Sales" />

                        <Text Label="Color" Initial="#AF8DC3" />

                   

                  In your Script.js

                  ......

                  function InitSettings() {

                  // General Settings

                  // Chart Object ID: used to create a Unique Chart ID

                  _this.ExtSettings.UniqueId = _this.Layout.ObjectId.replace("\\", "_");

                  // Use _this.ExtSettings.Color in your main script if you want to setup the color of something.

                  _this.ExtSettings.Color = _this.Layout.Text0.text;

                  }

                   

                  function InitData() {

                      

                       var dataset = [];

                       for (var i = 0; i < _this.Data.Rows.length; i++)

                       {

                             var vMaker     = _this.Data.Rows[i][0].text;

                             var vModel     = _this.Data.Rows[i][1].text;            

                             var vType       = _this.Data.Rows[i][2].text;

                             var vSales = parseInt(_this.Data.Rows[i][3].text);

                           

                             // I just put all data from the row into one node.       

                             dataset.push({"Maker":vMaker , "Model":vModel     , "Type":vType       , "Sales":vSales , "index":i});

                       }

                  ...

                   

                  Hopefully this helped.

                   

                  Sean

                    • Re: Re: Passing data from qv to extension

                      Thanks for the long explanation, definitely very helpful.

                       

                      So testing this out, it looks like this

                           <Dimension Label = "Model", Initial="Model" TargetName="Model"/>

                      doesnt output all the models for that corresponding Maker tho, it just outputs only 1 of the models. Is there a way to make it output all the Models for that selected Maker

                        • Re: Re: Re: Passing data from qv to extension
                          Sean (Hyunku) Cho

                          Try to think your data is coming in as a Straight Table.

                          MakerModelTypesum(Sales)
                          ToyotaCamrya luxury sedan1000
                          ToyotaCorollaa mid-size sedan500
                          HondaAccorda luxury sedan1000
                          HondaCivica mid-size sedan

                          500

                          Hundai
                          ...

                           

                          If you select Toyota,

                          MakerModelTypesum(Sales)
                          ToyotaCamrya luxury sedan1000
                          ToyotaCorollaa mid-size sedan500

                           

                          for (var i = 0; i < _this.Data.Rows.length; i++)

                               {

                                     var vMaker     = _this.Data.Rows[i][0].text;

                                     var vModel     = _this.Data.Rows[i][1].text;           

                                     var vType       = _this.Data.Rows[i][2].text;

                                     var vSales = parseInt(_this.Data.Rows[i][3].text);

                                  

                                     // I just put all data from the row into one node.      

                                     dataset.push({"Maker":vMaker , "Model":vModel     , "Type":vType       , "Sales":vSales , "index":i});

                               }

                          _this.Data.Rows.length = 2


                          Your dataset will have two records.

                          {"Maker":Toyota, "Model":"Camry", "Type":"a luxury sedan", "Sales":1000, "index":0}

                          {"Maker":Toyota, "Model":"Corolla", "Type":"a mid-size sedan", "Sales":500, "index":1}


                          I don't know what you are trying to do, but you need to handle the data from your JavaScript side to group or anything.


                          If you want a different format, then you need to modify the InitData() section. Add a loop for check Maker, then bring all Model into the JSON. 


                          {

                              { "Maker":"Toyota", Model : { Name: "Camry", "Type":"a luxury sedan", "Sales":"1000"}}

                              { "Maker":"Toyota", Model : { Name: "Corolla", "Type":"a mid-sizesedan", "Sales":"500"}}

                          }

                      • Re: Passing data from qv to extension
                        Clever Anjos

                        Think about your extension as a table.

                        QV will pass an array to your extension inside Data object