Maison > interface Web > js tutoriel > Comment introduire des graphiques électroniques dans Angular4 (exemple de code)

Comment introduire des graphiques électroniques dans Angular4 (exemple de code)

不言
Libérer: 2019-01-29 10:24:25
avant
3582 Les gens l'ont consulté

Le contenu de cet article concerne la méthode (exemple de code) d'introduction des echarts dans angulaire4. Il a une certaine valeur de référence. Les amis dans le besoin peuvent s'y référer.

1. Installez ngx-echarts

npm install echarts --save

npm install ngx-echarts --save

2. project echarts

1

2

3

4

5

6

7

8

9

10

11

//angular-cli.json文件

 

{

    "apps": [{

        "scripts":[

            "../node_modules/echarts/dist/echarts.min.js",

            "../node_modules/echarts/map/js/china.js",

            "../node_modules/echarts/dist/extension/bmap.js"

        ]

    }]

}

Copier après la connexion

3. Utilisez import NgxEchartsModule
echarts.module.ts

1

2

3

4

5

6

7

8

9

10

11

import { NgModule } from '@angular/core';

import { EchartsComponent } from './echarts/echarts.component';

import { NgxEchartsModule } from 'ngx-echarts';

 

@NgModule({

  imports: [

    NgxEchartsModule 

  ],

  declarations: [EchartsComponent],

})

export class EchartsModule { }

Copier après la connexion

echarts.component.ts

dans le module où vous avez vraiment besoin d'utiliser les instructions echarts

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

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

 

@Component({

  selector: 'app-echarts',

  templateUrl: './echarts.component.html',

  styleUrls: ['./echarts.component.scss']

})

export class EchartsComponent implements OnInit {

  showloading:boolean = true;

 

  constructor() { 

     

    setTimeout(()=> {

      this.showloading = false;

    }, 3000);

  }

 

  ngOnInit() {

  }

 

  chartOption = {

    title: {

      text: '堆叠区域图'

    },

    tooltip: {

      trigger: 'axis'

    },

    legend: {

      data: ['邮件营销''联盟广告''视频广告''直接访问''搜索引擎']

    },

    toolbox: {

      feature: {

        saveAsImage: {}

      }

    },

    grid: {

      left: '3%',

      right: '4%',

      bottom: '3%',

      containLabel: true

    },

    xAxis: [

      {

        type: 'category',

        boundaryGap: false,

        data: ['周一''周二''周三''周四''周五''周六''周日']

      }

    ],

    yAxis: [

      {

        type: 'value'

      }

    ],

    series: [

      {

        name: '邮件营销',

        type: 'line',

        stack: '总量',

        areaStyle: { normal: {} },

        data: [120, 132, 101, 134, 90, 230, 210]

      },

      {

        name: '联盟广告',

        type: 'line',

        stack: '总量',

        areaStyle: { normal: {} },

        data: [220, 182, 191, 234, 290, 330, 310]

      },

      {

        name: '视频广告',

        type: 'line',

        stack: '总量',

        areaStyle: { normal: {} },

        data: [150, 232, 201, 154, 190, 330, 410]

      },

      {

        name: '直接访问',

        type: 'line',

        stack: '总量',

        areaStyle: { normal: {} },

        data: [320, 332, 301, 334, 390, 330, 320]

      },

      {

        name: '搜索引擎',

        type: 'line',

        stack: '总量',

        label: {

          normal: {

            show: true,

            position: 'top'

          }

        },

        areaStyle: { normal: {} },

        data: [820, 932, 901, 934, 1290, 1330, 1320]

      }

    ]

  }

 

  Baroptions = {

    tooltip: {

      trigger: 'item',

      formatter: "{a} <br/>{b}: {c} ({d}%)"

    },

    legend: {

      orient: 'vertical',

      x: 'left',

      data: ['直达''营销广告''搜索引擎''邮件营销''联盟广告''视频广告''百度''谷歌''必应''其他']

    },

    series: [

      {

        name: '访问来源',

        type: 'pie',

        selectedMode: 'single',

        radius: [0, '30%'],

 

        label: {

          normal: {

            position: 'inner'

          }

        },

        labelLine: {

          normal: {

            show: false

          }

        },

        data: [

          { value: 335, name: '直达', selected: true },

          { value: 679, name: '营销广告' },

          { value: 1548, name: '搜索引擎' }

        ]

      },

      {

        name: '访问来源',

        type: 'pie',

        radius: ['40%''55%'],

 

        data: [

          { value: 335, name: '直达' },

          { value: 310, name: '邮件营销' },

          { value: 234, name: '联盟广告' },

          { value: 135, name: '视频广告' },

          { value: 1048, name: '百度' },

          { value: 251, name: '谷歌' },

          { value: 147, name: '必应' },

          { value: 102, name: '其他' }

        ]

      }

    ]

  }

 

 

 

  linkoption = {

    title: {

      text: '懒猫今日访问量'

    },

    color: ['#3398DB'],

    //气泡提示框,常用于展现更详细的数据

    tooltip: {

      trigger: 'axis',

      axisPointer: { // 坐标轴指示器,坐标轴触发有效

        type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'

      }

    },

    toolbox: {

      show: true,

      feature: {

        //显示缩放按钮

        dataZoom: {

          show: true

        },

        //显示折线和块状图之间的切换

        magicType: {

          show: true,

          type: ['bar''line']

        },

        //显示是否还原

        restore: {

          show: true

        },

        //是否显示图片

        saveAsImage: {

          show: true

        }

      }

    },

    grid: {

      left: '3%',

      right: '4%',

      bottom: '3%',

      containLabel: true

    },

    xAxis: [{

      type: 'category',

      data: [21231,1212,21231,3213],

      axisTick: {

        alignWithLabel: true

      },

      axisLabel: {

        interval: 0,

        rotate: 20

      },

    }],

    yAxis: [{

      name: "懒猫今日访问量",

      type: 'value'

    }],

    series: [{

      name: '今日访问次数',

      type: 'bar',

      barWidth: '60%',

      label: {

        normal: {

          show: true

        }

      },

      data:[21231,1212,21231,3213]

    }]

  }

 

 

  datamapvalue = [

       {name: '海门', value: [121.15,31.89,9]},

       {name: '鄂尔多斯', value: [109.781327,39.608266,12]},

       {name: '招远', value: [120.38,37.35,12]},

       {name: '舟山', value: [122.207216,29.985295,12]},

       {name: '齐齐哈尔', value: [123.97,47.33,14]},

       {name: '盐城', value: [120.13,33.38,15]},

       {name: '赤峰', value: [118.87,42.28,16]},

       {name: '青岛', value: [120.33,36.07,18]},

       {name: '乳山', value: [121.52,36.89,18]},

       {name: '金昌', value: [102.188043,38.520089,19]}

   ];

 

 

  mapoption = {

    backgroundColor: '#404a59',

    title: {

      text: '全国主要城市空气质量',

      subtext: 'data from PM25.in',

      sublink: 'http://www.pm25.in',

      left: 'center',

      textStyle: {

        color: '#fff'

      }

    },

    tooltip: {

      trigger: 'item'

    },

    legend: {

      orient: 'vertical',

      y: 'bottom',

      x: 'right',

      data: ['pm2.5'],

      textStyle: {

        color: '#fff'

      }

    },

    geo: {

      map: 'china',

      label: {

        emphasis: {

          show: false

        }

      },

      roam: true,

      itemStyle: {

        normal: {

          areaColor: '#323c48',

          borderColor: '#111'

        },

        emphasis: {

          areaColor: '#2a333d'

        }

      }

    },

    series: [

      {

        name: 'pm2.5',

        type: 'scatter',

        coordinateSystem: 'geo',

        data: this.datamapvalue,

        symbolSize: function (val) {

          return val[2] / 10;

        },

        label: {

          normal: {

            formatter: '{b}',

            position: 'right',

            show: false

          },

          emphasis: {

            show: true

          }

        },

        itemStyle: {

          normal: {

            color: '#ddb926'

          }

        }

      },

      {

        name: 'Top 5',

        type: 'effectScatter',

        coordinateSystem: 'geo',

        data: this.datamapvalue,

        symbolSize: function (val) {

          return val[2] / 10;

        },

        showEffectOn: 'render',

        rippleEffect: {

          brushType: 'stroke'

        },

        hoverAnimation: true,

        label: {

          normal: {

            formatter: '{b}',

            position: 'right',

            show: true

          }

        },

        itemStyle: {

          normal: {

            color: '#f4e925',

            shadowBlur: 10,

            shadowColor: '#333'

          }

        },

        zlevel: 1

      }

    ]

  }

 

}

Copier après la connexion

echarts.component.html

1

2

3

4

<div echarts [options] = "chartOption" [loading]="showloading" class="demo-chart"></div>

    <div echarts [options] = "Baroptions" [loading]="showloading" class="demo-chart"></div>

    <div echarts [options] = "linkoption" [loading]="showloading" class="demo-chart"></div>

    <div echarts [options] = "mapoption" [loading]="showloading" class="demo-chart"></div>

Copier après la connexion

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal