首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nativescript图表未显示

Nativescript图表未显示
EN

Stack Overflow用户
提问于 2018-11-15 04:13:21
回答 2查看 579关注 0票数 1

我是Nativescript的新手,目前正在使用javascript从事Nativescript项目。我正在探索图表选项,并使用'tns插件添加nativescript - UI图表‘命令安装了nativescript ui图表。当我试图显示一个简单的线条图时,我不会看到任何错误,但也不会显示任何错误。

这里是我的XML文件:

代码语言:javascript
复制
<Page class="page coverImage" navigatingTo="onNavigatingTo" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:chart="nativescript-ui-chart">
<Label text="Test Charts Page"></Label>
<StackLayout>    
<Label text="Test"></Label>
     <chart:RadCartesianChart class="m-t-10" height="500">
      <chart:RadCartesianChart.series>
        <chart:LineSeries
          items="{{ animeData }}"
          categoryProperty="season"
          valueProperty="count">
          <chart:LineSeries.horizontalAxis>
            <chart:CategoricalAxis labelFitMode="Rotate" />
          </chart:LineSeries.horizontalAxis>
          <chart:LineSeries.verticalAxis>
            <chart:LinearAxis labelLayoutMode="Outer" />
          </chart:LineSeries.verticalAxis>
        </chart:LineSeries>
      </chart:RadCartesianChart.series>
    </chart:RadCartesianChart>
  </StackLayout>
</Page>

我的javascript文件:

代码语言:javascript
复制
   var frameModule = require("ui/frame");
var Observable = require("data/observable").Observable;  
var pageData = new Observable();
pageData.animeData = [
 { season: "1", count: 82 }, { season: "2", count: 36 }, { season: "3", count: 41 },
 { season: "4", count: 52 }, { season: "5", count: 65 }, { season: "6", count: 40 },
 { season: "7", count: 52 }, { season: "8", count: 54 }, { season: "9", count: 47 },
 { season: "10", count: 52 }, { season: "11", count: 52 }, { season: "12", count: 53 },
 { season: "13", count: 34 }, { season: "14", count: 48 }, { season: "15", count: 49 },
 { season: "16", count: 45 }, { season: "17", count: 48 }, { season: "18", count: 45 },
 { season: "19", count: 47 }
];
exports.pageLoaded = function(args) 
{
     var page = args.object;
     page.bindingContext = pageData;
};

我在bundle.config中添加了nativescript-ui-图表如下:

代码语言:javascript
复制
global.registerModule("nativescript-ui-chart",
        () => require("../node_modules/nativescript-ui-chart"))

Package.json:

代码语言:javascript
复制
   {
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.pregapp4",
    "tns-ios": {
      "version": "4.0.1"
    }
  },
  "scripts": {
    "lint": "eslint \"app/**/*.js\""
  },
  "dependencies": {
    "nativescript-theme-core": "~1.0.4",
    "nativescript-ui-chart": "^3.9.1",
    "nativescript-ui-dataform": "^3.7.3",
    "nativescript-ui-listview": "^3.7.2",
    "nativescript-ui-sidedrawer": "^4.3.1",
    "tns-core-modules": "^5.0.2"
  },
  "devDependencies": {
    "eslint": "~4.9.0",
    "nativescript-dev-sass": "~1.5.0",
    "nativescript-dev-webpack": "~0.10.0",
    "webpack": "~3.10.0",
    "webpack-bundle-analyzer": "^2.9.1",
    "webpack-sources": "~1.1.0",
    "clean-webpack-plugin": "~0.1.19",
    "copy-webpack-plugin": "~4.3.0",
    "raw-loader": "~0.5.1",
    "css-loader": "~0.28.7",
    "nativescript-worker-loader": "~0.8.1",
    "resolve-url-loader": "~2.2.1",
    "extract-text-webpack-plugin": "~3.0.2",
    "uglifyjs-webpack-plugin": "~1.1.6",
    "sass-loader": "~6.0.6"
  }
}

在运行这个程序时,我没有得到错误,但是只有一个空白--不确定我遗漏了什么--任何帮助都将受到感谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-15 05:39:01

看起来数据模型没有被设置为可观察的。我已经将代码更改为在ios上运行良好。

代码语言:javascript
复制
var observableModule = require("tns-core-modules/data/observable");

function HomeViewModel() {
  var viewModel = observableModule.fromObject({
    animeData: [
      { season: "1", count: 82 }, { season: "2", count: 36 }, { season: "3", count: 41 },
      { season: "4", count: 52 }, { season: "5", count: 65 }, { season: "6", count: 40 },
      { season: "7", count: 52 }, { season: "8", count: 54 }, { season: "9", count: 47 },
      { season: "10", count: 52 }, { season: "11", count: 52 }, { season: "12", count: 53 },
      { season: "13", count: 34 }, { season: "14", count: 48 }, { season: "15", count: 49 },
      { season: "16", count: 45 }, { season: "17", count: 48 }, { season: "18", count: 45 },
      { season: "19", count: 47 }
    ],


  });

  return viewModel;
}

module.exports = HomeViewModel;

这里是操场链接,以防您想要添加一些内容。

票数 1
EN

Stack Overflow用户

发布于 2018-11-15 04:29:27

看起来你的插件路径需要修复

代码语言:javascript
复制
<Page class="page coverImage" navigatingTo="onNavigatingTo" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:chart="nativescript ui-chart">

应该是

代码语言:javascript
复制
<Page class="page coverImage" navigatingTo="onNavigatingTo" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:chart="nativescript-ui-chart">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53312335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档