cancel
Showing results for 
Search instead for 
Did you mean: 

Uncaught TypeError: Cannot read property 'setDataset' of undefined

Former Member
0 Kudos

Hello Experts,

I am getting some Unknown error

Can any one help me to solve this ??

here is my view code:

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"

  xmlns="sap.m" controllerName="demovizframe.V_chart"

  xmlns:viz="sap.viz.ui5.controls"

  xmlns:html="http://www.w3.org/1999/xhtml">

  <Page title="Title">

  <content>

  <viz:VizFrame xmlns="sap.viz" id="idcolumn" >

  </viz:VizFrame>

  </content>

  </Page>

</core:View>

my controller code :

var url2 ="http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/SENSOR_DETAILS1?$select=SO_TEXT_DT_MM_YYYY,HOU... eq '"+cval+"' &$format=json"; 

  var salesModel2 = new sap.ui.model.json.JSONModel();  

  salesModel2.loadData(url2);  

  var oVizFrame = this.getView().byId("idcolumn");

  var oDataset = new sap.viz.ui5.data.FlattenedDataset({

  dimensions : [{

  name : 'HOUR',

  value : "{HOUR}"}],

               

  measures : [{

  name : 'TEMP',

  value : '{ATM_TEMPERATURE}'} ],

             

  data : {

  path : "/d/results"

  }

  });

  oVizFrame.setDataset(oDataset);

  oVizFrame.setModel(salesModel2);

  oVizFrame.setVizType('line');

  oVizFrame.setVizProperties({

             plotArea: {

              colorPalette : d3.scale.category20().range()

                 }});

  var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({

       'uid': "valueAxis",

       'type': "Measure",

       'values': ["TEMP"]

     }),

     feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({

       'uid': "categoryAxis",

       'type': "Dimension",

       'values': ["HOUR"]

     });

  oVizFrame.addFeed(feedValueAxis);

  oVizFrame.addFeed(feedCategoryAxis);

Thanks in Advance,

Bharath

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think your oVizframe is undefined at the time you are trying to assign your dataset. When are you doing all the stuff in your controller? onInit/onBeforeRendering/onAfterRendering? The right time to do this would be onInit

Former Member
0 Kudos

Hi Pascal,

Inside onInit only

Regards,

Bharath

Former Member
0 Kudos

Then there must be another error or something is missing in your code.

cval would be undefined as well if this is all of your coding. Can you provide your running code (with the error) on jsbin, please?

Former Member
0 Kudos

hY pascal,

here i have attached my full code

Regrds,

Bharath

Former Member
0 Kudos

You are using the same controller for two different views. When loading the first view, the controller tries to get an element with the id "idcolumn", which is not available on view1.

You should better use a different controller for each view.

I can't exactly tell, if this fixes your problem as I'm getting a lot of errors cause of the invalid url. But when I remove the controller from the first view, the dataset is set correctly to the VizFrame

Former Member
0 Kudos

Can you please share that code with me ?

Regards,

Bharath

Former Member
0 Kudos

place your Page control inside App control in your second view.

Former Member
0 Kudos

NO Luck Rajeesh .!!

Former Member
0 Kudos

var oVizFrame = this.getView().byId("idcolumn");

after this place an alert(oVizFrame );

what you getting?

Former Member
0 Kudos

Undefined

Regards,

Bharath

Former Member
0 Kudos

yeah that is the problem...

try deleting one view or use

var oVizFrame = sap.ui.getCore().getControl("idcolumn");

dont use same controller for two views.

I just combined your two views and put this code in onInit method.

take a look

JS Bin - Collaborative JavaScript Debugging

Regards

Former Member
0 Kudos

I Have 2 combobox and both are connected,, and now i want to display a chart based on 2nd combobox selection, thats why i am using 2nd view for chart,, and can you please guide me how to write these two views in a single view ??

here is my first View code,


<mvc:View height="20%" controllerName="demovizframe.V_chart" xmlns:core="sap.ui.core"

          xmlns:mvc="sap.ui.core.mvc"  xmlns:suite="sap.suite.ui.commons" xmlns:viz="sap.viz.ui5.controls" xmlns:layout="sap.ui.layout" xmlns="sap.m">

<layout:Splitter width="100%" height="100%">

      <App>

        <Page title="SAMPLE TESTING CODE">

          <HBox justifyContent="SpaceAround">

            <HBox>

              <Label text="QUARTER:" class="LabelStyle" />

              <ComboBox id="idCombo" items="{OdataModel>/Location_details}" selectionChange="onChange">

                <core:Item text="{OdataModel>LM_LOCATION_ID_PK}"/>

              </ComboBox>

            </HBox>

            <HBox>

              <Label text="MONTH:" class="LabelStyle" />

              <ComboBox id="oComboBox" selectionChange="onSelect">

   </ComboBox>

            </HBox>

          </HBox> 

        </Page>

      </App>

</layout:Splitter>

    </mvc:View>

here is my 2nd view code,

<core:View controllerName="demovizframe.V_chart" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" 

  xmlns:viz="sap.viz.ui5.controls" xmlns="sap.m"> 

<App>

  <Page title="Title"> 

  <content> 

  <Label text="Product"/> 

  <ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%"> 

  <viz:Popover id="idPopOver"></viz:Popover> 

  <viz:VizFrame height="700px" id="idcolumn" uiConfig="{applicationSet:'fiori'}" vizType="line" width="100%"></viz:VizFrame> 

  </ScrollContainer> 

  </content> 

  </Page> 

</App>

</core:View> 

Regards,

Bharath

Former Member
0 Kudos

can you give samples for how your two odata responses look like?

Former Member
0 Kudos

Response in the Sense ??

Former Member
0 Kudos

Thank you Rajeesh

Answers (0)