预订演示

请注意 : 本帮助页面不适用于最新版本的Enterprise Architect. 最新的帮助文档在这里.

前页 后页

使用JSON的图表定义

您可能不希望自己编写动态图表,而是要提供图表的简单描述。动态图表可以由单个数据源设计和完全定义。 JSON是当前首选的数据源格式,但是将来会提供XML和其他格式。

您可以通过提供一个遵循DynamicChart模式的简单JSON数据结构来定义Chart。该架构在Schema Composer中可用。在Enterprise Architect示例模型的Dynamic Charts包中也可以轻松查看它。

(要查看DynamicChart Schema,请选择Develop> Schema Modeling> Schema Composer,单击“ Profile”字段中的Browse.按钮,然后选择DynamicChartSchema。)

数据源-JSON

To render a chart using a JSON data structure, first select the DynamicChart Artifact element, then open the 'internal code' editor.  For a selection in the Browser, right-click and choose 'Features > Edit Internal Code', or for a selection on a diagram, right-click and choose 'Edit Chart Script'. These will open the editor for you to edit the chart script. Create a JSON variable that defines the chart to render, then compose your ConstructChart function.

The ConstructChart function takes as its single argument the identity (a GUID string) of the Chart element being displayed on the opening diagram. You then call the built-in function ConstructChartFromJSON, passing the GUID as the first parameter and the JSON structure as the second argument, as illustrated in this example:

var barChart2DJSON =

{

  "Category" : "BarSmart",

  "Type" : "Simple",

  "Title" : "Vehicle Expenses",

  "Series" :

  [

     {

"Label" : "Fuel",

"Data":

{

"Type" : "Column",

"Points" :

[

{ "Category": "Jan", "Y": 1.0 },

{ "Category": "Feb", "Y": 3.0 },

{ "Category": "Mar", "Y": 7.0 },

{ "Category": "Apr", "Y": 8.0 },

{ "Category": "May", "Y": 10.0 },

{ "Category": "Jun", "Y": 15.0 }

]

}

},

{

"Label" : "Taxes",

"Data":

{

"Type" : "Normal",

"Points" :

[

{ "Y":10.0 },

{ "Y":12.0 },

{ "Y":16.0 },

{ "Y":17.0 },

{ "Y":10.0 },

{ "Y":12.0 }

]

}

},

{

"Label" : "Maintenance",

"Data":

{

"Type" : "Normal",

"Points" :

[

{ "Y":5.0 },

{ "Y":2.0 },

{ "Y":6.0 },

{ "Y":7.0 },

{ "Y":1.0 },

{ "Y":2.0 }

]

}

},

{

"Label" : "Other",

"Data":

{

"Type" : "Normal",

"Points" :

[

{ "Y":2.5 },

{ "Y":2.5 },

{ "Y":2.5 },

{ "Y":2.5 },

{ "Y":2.5 },

{ "Y":2.5 }

]

}

}

  ]

};

function ConstructChart(chartGuid)

{

ConstructChartFromJSON(chartGuid, barChart2DJSON);

}

Further JSON examples are provided in the Example Model.

Each Chart example provides a Dashboard diagram and DynamicChart element. Select an element from any of these examples and press Alt+7 to view the behavior behind the Chart. Looking at the variety of Chart examples is the best way to get to know how to use JSON to produce the types of Chart you might be interested in.