Home Web Front-end uni-app How to draw uniapp trajectory chart

How to draw uniapp trajectory chart

May 26, 2023 pm 01:57 PM

In mobile development, trajectory chart is one of the most commonly used functions. Uniapp is a cross-platform application development framework based on the Vue.js framework. It provides some components and plug-ins to facilitate application development. In Uniapp, you can use the u-charts plug-in to draw trajectory charts. This article will introduce how to use the u-charts plug-in to draw trajectory charts in Uniapp.

1. Install u-charts plug-in

To use u-charts plug-in, you need to install the plug-in first.

(1) Create Uniapp project in HBuilderX.

(2) In the project root directory, right-click and select "Select Workspace" to open the terminal.

(3) Enter npm install u-charts -S and press Enter to install.

2. Use the u-charts plug-in in the vue file

Next, introduce and use the u-charts plug-in in the vue file.

(1) In the vue file that needs to draw the trajectory map, reference the corresponding plug-in.

<template>
  <u-charts ref="uCharts" :canvas-id="'CanvasID'" :canvas-style="'width: 100%; height: 300px;'" :type="'line'" :extra="{line:{type:'curve'}}" :categories="categories" :series="series" :animation="true"></u-charts>
</template>

<script>
import uCharts from '@/components/u-charts/u-charts.vue'

export default {
  components: {
    uCharts
  },
  data () {
    return {
      categories: ['2011', '2012', '2013', '2014', '2015', '2016', '2017'],
      series: [{
        name: '成交量1',
        data: [15, 20, 45, 37, 4, 80, 92],
        color: '#4c9bfd',
        format: function (val) {
          return val.toFixed(2) + '万';
        }
      }, {
        name: '成交量2',
        data: [70, 40, 65, 100, 34, 18, 20],
        color: '#ff6347',
        format: function (val) {
          return val.toFixed(2) + '万';
        }
      }]
    }
  }
}
</script>
Copy after login

(2) Pass the corresponding data to the plug-in.

In the above code, we passed two data categories and series, where categories represents the X-axis of the trajectory chart, and series represents the Y-axis, including two data sets, namely "Trading Volume 1" and "Volume 2".

(3) Rendering plug-in.

Use Vue's life cycle function mounted to ensure that the DOM tree has been mounted before rendering u-charts, as shown below:

mounted () {
  this.$nextTick(function () {
    // 在渲染时初始化uCharts,按照官方文档格式传参
    let uCharts = this.$refs.uCharts;
    uCharts.init((canvas, width, height) => { });
  })
}
Copy after login

3. Advanced applications of trajectory charts

u-charts plug-in can not only draw trajectory charts, but also draw other forms of charts, such as bar charts, pie charts, etc. When drawing a trajectory graph, you can also use the setOption method provided by the plug-in to customize the trajectory graph more precisely. The following are some commonly used trajectory map customization operations.

(1) Set title and subtitle.

Use setOption to set the title and subtitle, as shown below:

let options = {
  title: {
    text: '轨迹图样例', // 主标题
    subtext: 'uniapp中的轨迹图插件使用', // 副标题
  },
  ...
};
uCharts.setOption(options);
Copy after login

(2) The bottom label of the X-axis of the trajectory chart is rotated.

When there is too much text in the bottom label of the X-axis of the trajectory chart, you can rotate the bottom label text at a certain angle to make the display effect better. Use the rotateLabel method as follows:

uCharts.rotateLabel({
  category?: string;
  degree?: number;
})
Copy after login

(3) Track map color rendering.

The color rendering of the trajectory map can be set separately according to the given data set. Use the setSeriesColors method to set the color of each data set as required, as shown below:

let colors = ['#4c9bfd', '#ff6347', '#398dcd', '#f99e1c', '#d5317c', '#3a71af', '#75b86c'];
uCharts.setSeriesColors(colors);
Copy after login

(4) Setting of track points.

The size and style of track points are adjustable. Use the setChartStyle method to set the track point size and track line color, as shown below:

uCharts.setChartStyle({
  good: {
    pointSize: 5,
    lineColor: '#4c9bfd'
  },
  bad: {
    pointSize: 5,
    lineColor: '#ff6347'
  }
})
Copy after login

The above introduction is only some of the operations in track chart drawing. The u-charts plug-in also provides a variety of chart drawings. and customization methods, please refer to u-charts official documentation for details.

To sum up, the u-charts plug-in is a very convenient and practical plug-in that can easily draw trajectory charts and finely customize them in the Uniapp framework.

The above is the detailed content of How to draw uniapp trajectory chart. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I use preprocessors (Sass, Less) with uni-app? How do I use preprocessors (Sass, Less) with uni-app? Mar 18, 2025 pm 12:20 PM

Article discusses using Sass and Less preprocessors in uni-app, detailing setup, benefits, and dual usage. Main focus is on configuration and advantages.[159 characters]

How do I use uni-app's animation API? How do I use uni-app's animation API? Mar 18, 2025 pm 12:21 PM

The article explains how to use uni-app's animation API, detailing steps to create and apply animations, key functions, and methods to combine and control animation timing.Character count: 159

What are the different types of testing that you can perform in a UniApp application? What are the different types of testing that you can perform in a UniApp application? Mar 27, 2025 pm 04:59 PM

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

How can you reduce the size of your UniApp application package? How can you reduce the size of your UniApp application package? Mar 27, 2025 pm 04:45 PM

The article discusses strategies to reduce UniApp package size, focusing on code optimization, resource management, and techniques like code splitting and lazy loading.

What debugging tools are available for UniApp development? What debugging tools are available for UniApp development? Mar 27, 2025 pm 05:05 PM

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

How do I use uni-app's storage API (uni.setStorage, uni.getStorage)? How do I use uni-app's storage API (uni.setStorage, uni.getStorage)? Mar 18, 2025 pm 12:22 PM

The article explains how to use uni-app's storage APIs (uni.setStorage, uni.getStorage) for local data management, discusses best practices, troubleshooting, and highlights limitations and considerations for effective use.

How do I use uni-app's API for accessing device features (camera, geolocation, etc.)? How do I use uni-app's API for accessing device features (camera, geolocation, etc.)? Mar 18, 2025 pm 12:06 PM

The article discusses using uni-app's APIs to access device features like camera and geolocation, including permission settings and error handling.Character count: 158

How do I validate user input in uni-app? How do I validate user input in uni-app? Mar 18, 2025 pm 12:17 PM

The article discusses validating user input in uni-app using JavaScript and data binding, emphasizing both client and server-side validation for data integrity. Plugins like uni-validate are recommended for form validation.

See all articles