@ejaszke/nativescript-highcharts
此插件允许您在 NativeScript 中使用 Highcharts。
npm i --save @ejaszke/nativescript-highcharts

nativescript-highcharts

此插件允许您在 NativeScript 中使用 Highcharts。

ns plugin add @ejaszke/nativescript-highcharts

信息:此插件与 NativeScript 7.0.0 及以上版本兼容。对于旧版本的 NativeScript,请查看此 仓库

屏幕截图

Demo IOS      Demo Android

Demo IOS      Demo Android

Demo IOS      Demo Android

Demo IOS      Demo Android

Demo IOS      Demo Android

示例应用

NativeScript-Core (XML)

查看 demo 文件夹。这是如何克隆和运行它的说明

git clone https://github.com/mhtghn/ns-plugins.git
cd ns-plugins
npm run setup
npm run start
> @mhtghn.nativescript-highcharts.build
npm run start
> apps.demo.ios # or apps.demo.android

NativeScript-Angular

查看 demo-angular 文件夹。这是如何克隆和运行它的说明

git clone https://github.com/mhtghn/ns-plugins.git
cd ns-plugins
npm run setup
npm run start
> @mhtghn.nativescript-highcharts.build
npm run start
> apps.demo-angular.ios # or apps.demo-angular.android

使用方法

NativeScript-Core

TypeScript

创建与普通 Highcharts 相同的 Highcharts 选项对象。您可以在 此处 找到所有可能的选项。然后将选项转换为字符串,因为现在您必须将选项作为字符串传递给插件。

...
export class HomeViewModel extends Observable {
chartOptions = {
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
};

get chartOptionsString(): string {
return JSON.stringify(this.chartOptions);
}
...
}

XML

<Page class="page"
navigatingTo="onNavigatingTo"
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:ui="@mhtghn/nativescript-highcharts">


<ActionBar class="action-bar">
<Label class="action-bar-title" text="Home"></Label>
</ActionBar>

<GridLayout>
<!-- Add your page content here -->
<ui:Highcharts options="{{chartOptionsString}}"></ui:Highcharts>
</GridLayout>
</Page>

NativeScript Angular

TypeScript

在您的模块中导入 HighchartsModule。

...
import { HighchartsModule } from '@mhtghn/nativescript-highcharts/angular';

@NgModule({
imports: [
...
HighchartsModule
],
...
})
export class HomeModule { }

创建与普通 Highcharts 相同的 Highcharts 选项对象。您可以在 此处 找到所有可能的选项。然后将选项转换为字符串,因为现在您必须将选项作为字符串传递给插件。

import { Component, OnInit } from "@angular/core";

@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {
chartOptions = {
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
};

get chartOptionsString(): string {
return JSON.stringify(this.chartOptions);
}
...
}

HTML

<ActionBar class="action-bar">
<ActionBar class="action-bar">
<Label class="action-bar-title" text="Home"></Label>
</ActionBar>

<GridLayout class="page">
<!-- Add your page content here -->
<Highcharts options="{{chartOptionsString}}"></Highcharts>
</GridLayout>

Highcharts 兼容性

  • highcharts.js:v8.2.0
  • highcharts-more.js:v8.2.0
  • highcharts-3d.js:v8.2.0
  • sankey.js:v8.2.0
  • organization.js:v8.2.0

提示

  • 将以下选项添加到图表选项中,以禁用在 webview 中显示 Highcharts.com Hyperlink
    credits: {
    enabled: false;
    }

致谢

此插件深受 此示例 的启发,来自 Eddy Verbruggen

许可

Apache 许可证第 2 版