[英]Reading JSON in joint.js?
I want joint.js library to read my JSON and display it as a chart... 我想让joint.js库读取我的JSON并将其显示为图表...
var paper = new joint.dia.Paper({
el: $('#paper'),
width: 600,
height: 200,
model: graph
});
var graph = new joint.dia.Graph;
jsonstring = '{"employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] }';
graph.fromJSON(JSON.parse(jsonstring));
From the API for joint.dia.Graph : 来自joint.dia.Graph的API:
joint.dia.Graph is the model holding all the cells (elements and links) of the diagram. joint.dia.Graph是包含图表所有单元格(元素和链接)的模型。 It's a Backbone model . 这是一个Backbone模型 。 The collection of all the cells is stored in the property cells. 所有单元格的集合都存储在属性单元格中。
So the expected JSON should be in this form: { cells: [] }
. 所以预期的JSON应该采用以下形式: { cells: [] }
。 Where cells
is an array of both elements and links. 其中, cells
是元素和链接的数组。 Each element should have the form: 每个元素都应该具有以下形式:
{
id: <string>,
type: '<type of shape>',
attrs: { <attrs> },
position: { x: <int>, y: <int> },
angle: <deg>,
size: { width: <int>, height: <int> },
z: <int>,
... and some other, maybe custom, data properties
}
Reference: Using Server Data with JointJS 参考: 将服务器数据与JointJS一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.