Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Nativescript图表属性从json文件加载到xml文件?_Json_Xml_Nativescript - Fatal编程技术网

如何将Nativescript图表属性从json文件加载到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

我想将Nativescript(RadCartesianChart)属性从外部json文件加载到我的主xml文件中。如何从外部json文件调用此RadCartesianChart属性? 外部json文件应如下所示: { “标题”:“图表”, “图表类型”:“线条”, “x轴”:“月份”, “y轴”:“金额” }

这是我当前的xml文件:

<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