mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 22:10:11 +00:00
增加ScatterChart散点图
This commit is contained in:
@@ -176,7 +176,9 @@ namespace XCharts
|
||||
{
|
||||
var xdata = serie.xData[n];
|
||||
var ydata = serie.yData[n];
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < 5 && Mathf.Abs(yValue - ydata) / yRate < 5)
|
||||
var symbolSize = serie.symbol.GetSize(serie.data[n].data);
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
||||
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
||||
{
|
||||
m_Tooltip.dataIndex[i] = n;
|
||||
serie.selected = true;
|
||||
|
||||
@@ -47,11 +47,7 @@ namespace XCharts
|
||||
m_ItemWidth = 60.0f,
|
||||
m_ItemHeight = 20.0f,
|
||||
m_ItemGap = 5,
|
||||
m_ItemFontSize = 16,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"serie1"
|
||||
}
|
||||
m_ItemFontSize = 16
|
||||
};
|
||||
legend.location.top = 30;
|
||||
return legend;
|
||||
|
||||
26
Scripts/UI/Internal/Scatter.cs
Normal file
26
Scripts/UI/Internal/Scatter.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Scatter
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_InsideRadius;
|
||||
[SerializeField] private float m_OutsideRadius;
|
||||
[SerializeField] private float m_TooltipExtraRadius;
|
||||
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
|
||||
public static Scatter defaultScatter
|
||||
{
|
||||
get
|
||||
{
|
||||
var scatter = new Scatter
|
||||
{
|
||||
};
|
||||
return scatter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/Internal/Scatter.cs.meta
Normal file
11
Scripts/UI/Internal/Scatter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd59b655decf420ca27dfb742be4fdf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -283,8 +283,7 @@ namespace XCharts
|
||||
Color color = m_Radar.backgroundColorList[i % m_Radar.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
ChartHelper.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, m_Radar.lineTickness,
|
||||
m_Radar.lineColor);
|
||||
ChartHelper.DrawCicleNotFill(vh, p, outsideRadius, m_Radar.lineTickness, m_Radar.lineColor);
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
|
||||
96
Scripts/UI/ScatterChart.cs
Normal file
96
Scripts/UI/ScatterChart.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[AddComponentMenu("XCharts/ScatterChart", 17)]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class ScatterChart : CoordinateChart
|
||||
{
|
||||
[SerializeField] private Scatter m_Scatter = Scatter.defaultScatter;
|
||||
|
||||
public Scatter scatter { get { return m_Scatter; } }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
m_Scatter = Scatter.defaultScatter;
|
||||
m_Title.text = "ScatterChart";
|
||||
m_Tooltip.type = Tooltip.Type.None;
|
||||
m_XAxises[0].type = Axis.AxisType.Value;
|
||||
m_XAxises[0].boundaryGap = false;
|
||||
m_YAxises[1].type = Axis.AxisType.Value;
|
||||
m_XAxises[1].boundaryGap = false;
|
||||
RemoveData();
|
||||
AddSerie("serie1", SerieType.Scatter);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
AddXYData(0, Random.Range(10, 100), Random.Range(10, 100));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
HashSet<string> serieNameSet = new HashSet<string>();
|
||||
int serieNameCount = -1;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.series[i];
|
||||
serie.index = i;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (string.IsNullOrEmpty(serie.name)) serieNameCount++;
|
||||
else if (!serieNameSet.Contains(serie.name))
|
||||
{
|
||||
serieNameSet.Add(serie.name);
|
||||
serieNameCount++;
|
||||
}
|
||||
if (serie.dataCount <= 0 || !serie.show)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.dataCount ? serie.dataCount : maxShowDataNumber)
|
||||
: serie.dataCount;
|
||||
int dataCount = (maxCount - minShowDataNumber);
|
||||
for (int n = minShowDataNumber; n < maxCount; n++)
|
||||
{
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(n, m_DataZoom, out xValue, out yValue);
|
||||
float pX = coordinateX + m_Coordinate.tickness;
|
||||
float pY = coordinateY + m_Coordinate.tickness;
|
||||
float xDataHig = (xValue - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
float yDataHig = (yValue - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
var color = m_ThemeInfo.GetColor(serieNameCount);
|
||||
color.a = 200;
|
||||
var datas = serie.data[n].data;
|
||||
float symbolSize = 0;
|
||||
if (serie.selected && n == m_Tooltip.dataIndex[serie.axisIndex])
|
||||
{
|
||||
symbolSize = serie.symbol.GetSelectedSize(datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbolSize = serie.symbol.GetSize(datas);
|
||||
}
|
||||
if (symbolSize > 100) symbolSize = 100;
|
||||
DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
|
||||
}
|
||||
if (vh.currentVertCount > 60000)
|
||||
{
|
||||
m_Large++;
|
||||
Debug.LogError("large:" + m_Large + "," + vh.currentVertCount);
|
||||
RefreshChart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/UI/ScatterChart.cs.meta
Normal file
11
Scripts/UI/ScatterChart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf16aac0bd6c24a8da75846c34c5193e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -8,7 +9,7 @@ namespace XCharts
|
||||
{
|
||||
public static class ChartHelper
|
||||
{
|
||||
private static float CRICLE_SMOOTHNESS = 1f;
|
||||
public static float CRICLE_SMOOTHNESS = 2.5f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
|
||||
public static void HideAllObject(GameObject obj, string match = null)
|
||||
@@ -240,13 +241,13 @@ namespace XCharts
|
||||
vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
|
||||
}
|
||||
|
||||
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
int segments = 0, bool fill = true)
|
||||
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color, int segments = 0)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
if (segments < 3) segments = 3;
|
||||
DrawSector(vh, p, radius, color, 0, 360, segments);
|
||||
}
|
||||
|
||||
@@ -450,12 +451,29 @@ namespace XCharts
|
||||
int startIndex = jsonData.IndexOf("[");
|
||||
int endIndex = jsonData.IndexOf("]");
|
||||
string temp = jsonData.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
string[] datas = temp.Split(',');
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
Debug.LogError("temp:"+temp);
|
||||
if (temp.IndexOf("],") > -1 || temp.IndexOf("] ,") > -1)
|
||||
{
|
||||
list.Add(float.Parse(datas[i].Trim()));
|
||||
string[] datas = temp.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
temp = datas[i];
|
||||
Debug.LogError("split:" + temp);
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
else
|
||||
{
|
||||
string[] datas = temp.Split(',');
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
list.Add(float.Parse(datas[i].Trim()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<string> ParseStringFromString(string jsonData)
|
||||
|
||||
Reference in New Issue
Block a user