日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

XCharts图表插件,LineChart折线图,删除折线点功能

發(fā)布時(shí)間:2024/1/18 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XCharts图表插件,LineChart折线图,删除折线点功能 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

XCharts圖表插件,在折線圖上刪除點(diǎn)

一、前言
XCharts插件,在使用中發(fā)現(xiàn),可以在折線圖上添加點(diǎn),移除所有點(diǎn),但并沒(méi)有移除單個(gè)點(diǎn)的功能。
二、思路
1,首先我們要知道,在折線圖上添加的點(diǎn),點(diǎn)的數(shù)據(jù)信息都存在了lineChart.series.GetSerie(0).data里面。
2,其次經(jīng)過(guò)嘗試,發(fā)現(xiàn)api里雖然沒(méi)有直接給我們點(diǎn)的位置信息(x,y的值),但每個(gè)點(diǎn)都有一個(gè)label,給了我們label的位置信息(labelPosition)
3,然后我們要知道每個(gè)點(diǎn)是一個(gè)圓形,鼠標(biāo)放上去,點(diǎn)會(huì)被放大,點(diǎn)被選中時(shí)的大小api中也給了。(selectSize)
4,刪除點(diǎn)其實(shí)就是把此點(diǎn)在lineChart.series.GetSerie(0).data中的信息給移除掉
5,知道以上4點(diǎn)內(nèi)容,相信大家都知道該咋解決了吧。
代碼邏輯:
點(diǎn)擊鼠標(biāo)左鍵,獲取鼠標(biāo)點(diǎn)擊的位置,用 鼠標(biāo)點(diǎn)擊位置x的值 減去 點(diǎn)標(biāo)簽位置的x值,并 取其絕對(duì)值(y值同理);用 此絕對(duì)值 與 點(diǎn)被選中時(shí)的大小 做比較。
如果 兩個(gè)絕對(duì)值 都 小于 此點(diǎn)被選中時(shí)的大小,那么鼠標(biāo)點(diǎn)中了,移除此點(diǎn)在lineChart.series.GetSerie(0).data中的信息。刪除點(diǎn)成功。
三、代碼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using XCharts;
public class NewBehaviourScript : MonoBehaviour
{
public LineChart lineChart;
public float selectSize = 10f;
List serieDatas = new List();
// Start is called before the first frame update
void Start()
{
PointInit();
}

/// <summary> /// 小圓點(diǎn)初始化 /// </summary> void PointInit() {lineChart.series.GetSerie(0).label.show = true;lineChart.series.GetSerie(0).label.textStyle.fontSize = -1;lineChart.series.GetSerie(0).symbol.selectedSize = selectSize; }/// <summary> /// 移除小圓點(diǎn) /// </summary> void RemovePoint() {if (Input.GetMouseButtonDown(0)){Vector2 mousePos = new Vector2(Input.mousePosition.x - Screen.width / 2f, Input.mousePosition.y - Screen.height / 2f);//Debug.Log("鼠標(biāo)" + mousePos);foreach (var item in lineChart.series.GetSerie(0).data){if (Mathf.Abs(mousePos.x - item.labelPosition.x) < selectSize && Mathf.Abs(mousePos.y - item.labelPosition.y) < selectSize){Debug.Log("點(diǎn)中了");lineChart.series.GetSerie(0).data.Remove(item);return;}}} }// Update is called once per frame void Update() {RemovePoint(); }

}

總結(jié)

以上是生活随笔為你收集整理的XCharts图表插件,LineChart折线图,删除折线点功能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。