javascript - SAPUI5 VIZ 柱形图集成。无效的数据绑定(bind)错误

标签 javascript data-binding charts sapui5 graphviz

我试图显示来自 SAPUI5 的 VIZ 图表,但无法绑定(bind)从模型接收的数据。它会抛出[50017] - 无效数据绑定(bind)错误。我在下面发布了我的代码,请查看它并帮助我找到原因。

var assignedContentData = {
    "AssignedContentData": [{
        "description": "Capital",
        "newsletter": 2,
        "press_release": 12,
        "letter": 1,
        "notice": 0,
        "bulletin_memorandum": 0
    }, {
        "description": "NA",
        "newsletter": 0,
        "press_release": 0,
        "letter": 0,
        "notice": 1,
        "bulletin_memorandum": 0
    }, {
        "description": "Equity",
        "newsletter": 0,
        "press_release": 4,
        "letter": 0,
        "notice": 5,
        "bulletin_memorandum": 12
    }]
};

var oAssignContentModel = new sap.ui.model.json.JSONModel({
    data: assignedContentData
});

sap.ui.getCore().setModel(oAssignContentModel, "oAssignContentModel");
var assignedContentBarChart = new sap.viz.ui5.controls.VizFrame("assignedContentBarChart", {
    vizType: "stacked_column"
});

var oDatasetAssignedContentBar = new sap.viz.ui5.data.FlattenedDataset({
    dimensions: [{
        name: "Description",
        value: "{description}"
    }],
    measures: [{
        name: "Newsletter",
        value: "{newsletter}"
    }],
    data: {
        path: "/data/AssignedContentData"
    }
});

var feedValueAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
    'uid': "valueAxis",
    'type': "Measure",
    'values': ["Newsletter"]
});
var feedCategoryAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
    'uid': "categoryAxis",
    'type': "Dimension",
    'values': ["Description"]
});
var feedColorAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
    'uid': "color",
    'type': "Dimension",
    'values': ["Newsletter", "Press_Release", "Letter", "Notice", "Bulletin_memorandum"]
});
assignedContentBarChart.setVizProperties({
    plotArea: {
        dataLabel: {
            visible: true,
            formatString: "#,##0"
        }
    },
    legend: {
        title: {
            visible: false
        }
    },

    title: {
        visible: true,
        text: 'Bar Chart'
    }
});

assignedContentBarChart.setDataset(oDatasetAssignedContentBar);
assignedContentBarChart.addFeed(feedValueAxis1);
assignedContentBarChart.addFeed(feedCategoryAxis1);

最佳答案

您的绑定(bind)不正确。由于您的模型名称是 oAssignContentModel,因此它也必须反射(reflect)在绑定(bind)中以及 data 属性分配中:

var oDatasetAssignedContentBar = new sap.viz.ui5.data.FlattenedDataset({
    dimensions: [{
        name: "Description",
        value: "{description}"
    }],
    measures: [{
        name: "Newsletter",
        value: "{newsletter}"
    }],
    data: {
        path: "oAssignContentModel>/data/AssignedContentData"
    }
});

或者您可以从模型中删除该名称,并保留数据绑定(bind)现在的样子:

sap.ui.getCore().setModel(oAssignContentModel);

关于javascript - SAPUI5 VIZ 柱形图集成。无效的数据绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37961925/

相关文章:

javascript - OOP javascript,从方法中的AJAX 'statement',如何调用该类的另一个方法?

javascript - Dropzone JS 通过 JS 函数添加缩略图 - TypeError : this. defaultOptions 未定义

data-binding - Backbone : Model-to-template and template-to-model binding

javascript - 使用 KnockoutJS 数据未绑定(bind)到表

javascript - 范围问题 Javascript (self, this)

javascript - 使用 javascript api 显示 dropbox 中的图像

c# - 绑定(bind)到不带参数的成员函数?

javascript - iOS 设备上不显示 Google 图表

java - 如何使用Jzy3d java 3d图表库?

c# - 在 MSChart 控件上绘制