Skip to Content

how to bind chart dynamically?

I am representing a table data via a vizframe chart. When I am calling the chart for the first time its working fine but if after that I am entering data into table and then again displaying the chart its showing a "invalid data binding" error. chrt.png. Even if I dont enter data second time and just pressing the button show chart then also its showing the same error!!! Can anybody please help? Thanks!

here is my code in controler

onPresschart:function(){


 var model = new sap.ui.model.json.JSONModel();
 var oData = sap.ui.getCore().getModel("jModel").getData();
 model.setData(oData);

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

var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [{
name : 'type',
value : "{type}"}],


measures : [{
name : 'hours',
value : '{hours}'} ],


data : {
path : "/"
}
});
oVizFrame.setDataset(oDataset);
oVizFrame.setModel(model);
oVizFrame.setVizType('bar');
//set viz properties
oVizFrame.setVizProperties({ 
plotArea: {
colorPalette : d3.scale.category20().range()
}});


var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "valueAxis",
'type': "Measure",
'values': ["hours"]
}),
feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "categoryAxis",
'type': "Dimension",
'values': ["type"]
});
oVizFrame.addFeed(feedValueAxis);
oVizFrame.addFeed(feedCategoryAxis);


 


//oTable.bindItems("jModel>/d"); 
}
chrt.png (108.4 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 23, 2017 at 08:55 AM

    Maybe I get your error. The thing is that the data is getting bound to the chart more than once, which is causing redundancies and hence you are getting that error. I would suggest you to bind the data to the chart from the model and on submit change the model data and instead of binding the data to the chart again, just refresh the model. So in this way, only once the data binding happens.

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

    • thanks for the response! it has been solved when i changed the code like this:

      	var model=newsap.ui.model.json.JSONModel();//sap.ui.getCore().getModel("jModel").getData();
      	var aData=sap.ui.getCore().getModel("jModel").getData();
      	model.setData(aData);
      var oChart = this.getView().byId("idcolumn");
      	oChart.getModel().setProperty("/", aData);