如何将Nativescript图表属性从json文件加载到xml文件?
我想将Nativescript(RadCartesianChart)属性从外部json文件加载到我的主xml文件中。如何从外部json文件调用此RadCartesianChart属性? 外部json文件应如下所示: { “标题”:“图表”, “图表类型”:“线条”, “x轴”:“月份”, “y轴”:“金额” } 这是我当前的xml文件:如何将Nativescript图表属性从json文件加载到xml文件?,json,xml,nativescript,Json,Xml,Nativescript,我想将Nativescript(RadCartesianChart)属性从外部json文件加载到我的主xml文件中。如何从外部json文件调用此RadCartesianChart属性? 外部json文件应如下所示: { “标题”:“图表”, “图表类型”:“线条”, “x轴”:“月份”, “y轴”:“金额” } 这是我当前的xml文件: <Page loaded="pageLoaded" class="page" xmlns="http://www.nativescript.org/t
<Page
loaded="pageLoaded" class="page"
xmlns="http://www.nativescript.org/tns.xsd"
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:sd="nativescript-pro-ui/sidedrawer"
xmlns:chart="nativescript-pro-ui/chart"
>
<ActionBar title="MyApp" class="action-bar"/>
<StackLayout class="home-panel">
<Label textWrap="true" text="OVERVIEW" class="overview"/>
<Label textWrap="true" text="Sales Report" class="graph-desc"/>
<GridLayout class= "gLayout" rows="*" height="800px" width="1300px">
<chart:RadCartesianChart row="0">
<chart:RadCartesianChart.series class="Line">
<chart:LineSeries items="{{ categoricalSource }}" categoryProperty="{{ categoryProperty }}" valueProperty="{{ valueProperty }}">
<chart:LineSeries.horizontalAxis>
<chart:CategoricalAxis/>
</chart:LineSeries.horizontalAxis>
<chart:LineSeries.verticalAxis>
<chart:LinearAxis/>
</chart:LineSeries.verticalAxis>
</chart:LineSeries>
</chart:RadCartesianChart.series>
</chart:RadCartesianChart>
</GridLayout>
<GridLayout rows="*" xmlns:chart="nativescript-pro-ui/chart" height="800px" width="1300px">
<chart:RadPieChart row="0" allowAnimation="true" row="0">
<chart:RadPieChart.series>
<chart:PieSeries selectionMode="DataPoint" expandRadius="0.4" outerRadiusFactor="0.7" items="{{ categoricalSource }}" valueProperty="Amount"
legendLabel="Department" />
</chart:RadPieChart.series>
<chart:RadPieChart.legend>
<chart:RadLegendView position="Right" title="Dep" offsetOrigin="TopRight" width="110" enableSelection="true" />
</chart:RadPieChart.legend>
</chart:RadPieChart>
</GridLayout>
</StackLayout>
根据
在js文件中添加
// Either import your JSON here or...
var OptionsModel = require("./test.json");
// call GetString to get it from server or external source.
// and add it to OptionsModel.
// All the variables you wish to import in the xml add it to pageBinding as an object.
// then you can use {{'options or model or whatever name you give'.'value you want to access inside it'}}
page.bindingContext = {
model: homeViewModel,
options: OptionsModel
};
在xml中添加
{{ model.categoricalSource }} or {{options.title}} to access values