# ohos-MPChart **Repository Path**: zhao-hui7000/ohos-MPChart ## Basic Information - **Project Name**: ohos-MPChart - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2022-03-02 - **Last Updated**: 2024-06-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MPAndroidChart **本项目是基于开源项目MPAndroidChart的功能进行ets开发,可以通过项目标签以及github地址( https://github.com/PhilJay/MPAndroidChart )追踪到原项目版本** #### 项目介绍 - 项目名称:MPAndroidChart - 所属系列:ohos的第三方组件ets开发 - 功能:自定义图表视图库 - 项目开发状态:完成 - 调用差异:无 - 项目作者和维护人:hihope - 联系方式:hihope@hoperun.com - 原项目Doc地址:https://github.com/PhilJay/MPAndroidChart - 原项目基线版本:3.1.0; sha1:0550d3f7907c635744c08ad8ff9c45e1b6281cc7; - 编程语言:ets - 外部库依赖:无 #### 效果展示: #### 安装教程 ##### 方案一: 1. 下载MPAndroidChart源码。 2. 拷贝MPAndroidChart源码中common目录代码到default目录下。 3. 在demo中引用。 #### 使用说明 1、初始化数据 ``` private aboutToAppear() { this.lineData = this.initCurveData(45, 100); this.topAxis.setLabelCount(6, false); this.topAxis.setPosition(XAxisPosition.TOP); this.topAxis.setAxisMinimum(this.lineData.getXMin()); this.topAxis.setAxisMaximum(this.lineData.getXMax()); this.bottomAxis.setLabelCount(6, false); this.bottomAxis.setPosition(XAxisPosition.BOTTOM); this.bottomAxis.setAxisMinimum(this.lineData.getXMin()); this.bottomAxis.setAxisMaximum(this.lineData.getXMax()); this.leftAxis = new YAxis(AxisDependency.LEFT); this.leftAxis.setLabelCount(5, false); this.leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART); this.leftAxis.setSpaceTop(15); this.leftAxis.setAxisMinimum(this.lineData.getYMin()); this.leftAxis.setAxisMaximum(this.lineData.getYMax()); this.rightAxis = new YAxis(AxisDependency.RIGHT); this.rightAxis.setDrawGridLines(false); this.rightAxis.setLabelCount(7, false); this.rightAxis.setSpaceTop(15); this.rightAxis.setAxisMinimum(this.lineData.getYMin()); // this replaces setStartAtZero(true) this.rightAxis.setAxisMaximum(this.lineData.getYMax()); } private initCurveData(count: number, range: number): LineData { let values = new JArrayList(); values.add(new EntryOhos(0, 0)); values.add(new EntryOhos(50, 100)); values.add(new EntryOhos(100, 40)); values.add(new EntryOhos(150, 120)); values.add(new EntryOhos(250, 0)); let values2 = new JArrayList(); values2.add(new EntryOhos(10, 0)); values2.add(new EntryOhos(60, 100)); values2.add(new EntryOhos(110, 40)); values2.add(new EntryOhos(160, 100)); values2.add(new EntryOhos(210, 0)); let values3 = new JArrayList(); values3.add(new EntryOhos(30, 0)); values3.add(new EntryOhos(80, 100)); values3.add(new EntryOhos(130, 40)); values3.add(new EntryOhos(180, 100)); values3.add(new EntryOhos(230, 0)); let dataSet = new JArrayList(); let set1 = new LineDataSet(values, "DataSet 1"); set1.setColorByColor(Color.Orange); set1.setFormSize(10); set1.setForm(LegendForm.SQUARE); set1.setFormLineWidth(12); dataSet.add(set1); return new LineData(dataSet) } ``` 2、添加数据到自定义曲线图表组件 ``` build() { Stack({ alignContent: Alignment.TopStart }) { LineChart({ topAxis: this.topAxis, bottomAxis: this.bottomAxis, width: this.width, height: this.height, minOffset: this.minOffset, leftAxis: this.leftAxis, rightAxis: this.rightAxis, lineData: this.lineData, }) } } ``` #### 版本迭代 - v1.0.0 - 已实现功能 1、自定义曲线图表组件 #### 版权和许可信息 /* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */