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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

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

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

XCharts圖表插件,在折線圖上刪除點

一、前言
XCharts插件,在使用中發(fā)現(xiàn),可以在折線圖上添加點,移除所有點,但并沒有移除單個點的功能。
二、思路
1,首先我們要知道,在折線圖上添加的點,點的數(shù)據(jù)信息都存在了lineChart.series.GetSerie(0).data里面。
2,其次經(jīng)過嘗試,發(fā)現(xiàn)api里雖然沒有直接給我們點的位置信息(x,y的值),但每個點都有一個label,給了我們label的位置信息(labelPosition)
3,然后我們要知道每個點是一個圓形,鼠標(biāo)放上去,點會被放大,點被選中時的大小api中也給了。(selectSize)
4,刪除點其實就是把此點在lineChart.series.GetSerie(0).data中的信息給移除掉
5,知道以上4點內(nèi)容,相信大家都知道該咋解決了吧。
代碼邏輯:
點擊鼠標(biāo)左鍵,獲取鼠標(biāo)點擊的位置,用 鼠標(biāo)點擊位置x的值 減去 點標(biāo)簽位置的x值,并 取其絕對值(y值同理);用 此絕對值 與 點被選中時的大小 做比較。
如果 兩個絕對值 都 小于 此點被選中時的大小,那么鼠標(biāo)點中了,移除此點在lineChart.series.GetSerie(0).data中的信息。刪除點成功。
三、代碼
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> /// 小圓點初始化 /// </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> /// 移除小圓點 /// </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("點中了");lineChart.series.GetSerie(0).data.Remove(item);return;}}} }// Update is called once per frame void Update() {RemovePoint(); }

}

總結(jié)

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

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