mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
折线图增加更多参数配置
This commit is contained in:
@@ -5,13 +5,35 @@ using UnityEngine.UI;
|
||||
|
||||
namespace xcharts
|
||||
{
|
||||
[System.Serializable]
|
||||
public enum PointType
|
||||
{
|
||||
square,
|
||||
cicle
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class LineData
|
||||
{
|
||||
public bool smooth = false;
|
||||
public bool area = false;
|
||||
public float pointWid = 1;
|
||||
|
||||
public float tickness = 0.8f;
|
||||
|
||||
[Header("Point")]
|
||||
public bool showPoint = true;
|
||||
public PointType pointType = PointType.square;
|
||||
public float pointWid = 1.0f;
|
||||
public Color pointColor = Color.white;
|
||||
|
||||
[Header("Smooth")]
|
||||
public bool smooth = false;
|
||||
|
||||
[Range(1f, 10f)]
|
||||
public float smoothStyle = 2f;
|
||||
|
||||
[Header("Area")]
|
||||
public bool area = false;
|
||||
public Color areaStartColor;
|
||||
public Color areaToColor;
|
||||
}
|
||||
|
||||
public class LineChart : BaseChart
|
||||
@@ -34,7 +56,7 @@ namespace xcharts
|
||||
base.OnPopulateMesh(vh);
|
||||
int seriesCount = seriesList.Count;
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = coordinateWid / (xAxis.scaleNum - 1);
|
||||
float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!legend.IsShowSeries(j)) continue;
|
||||
@@ -52,10 +74,10 @@ namespace xcharts
|
||||
{
|
||||
if (lineData.smooth)
|
||||
{
|
||||
var list = ChartUtils.GetBezierList(lp, np);
|
||||
var list = ChartUtils.GetBezierList(lp, np, lineData.smoothStyle);
|
||||
Vector3 start, to;
|
||||
start = list[0];
|
||||
for(int k = 1; k < list.Count; k++)
|
||||
for (int k = 1; k < list.Count; k++)
|
||||
{
|
||||
to = list[k];
|
||||
ChartUtils.DrawLine(vh, start, to, lineData.tickness, color);
|
||||
@@ -67,20 +89,32 @@ namespace xcharts
|
||||
ChartUtils.DrawLine(vh, lp, np, lineData.tickness, color);
|
||||
if (lineData.area)
|
||||
{
|
||||
ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY), color);
|
||||
ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY), new Vector3(lp.x, zeroY),
|
||||
lineData.areaStartColor,lineData.areaToColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
lp = np;
|
||||
}
|
||||
// draw point
|
||||
for (int i = 0; i < series.dataList.Count; i++)
|
||||
if (lineData.showPoint)
|
||||
{
|
||||
SeriesData data = series.dataList[i];
|
||||
for (int i = 0; i < series.dataList.Count; i++)
|
||||
{
|
||||
SeriesData data = series.dataList[i];
|
||||
|
||||
Vector3 p = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max);
|
||||
ChartUtils.DrawPolygon(vh, p, lineData.pointWid, Color.white);
|
||||
Vector3 p = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max);
|
||||
switch (lineData.pointType)
|
||||
{
|
||||
case PointType.square:
|
||||
ChartUtils.DrawPolygon(vh, p, lineData.pointWid, lineData.pointColor);
|
||||
break;
|
||||
case PointType.cicle:
|
||||
ChartUtils.DrawCricle(vh, p, lineData.pointWid, lineData.pointColor, (int)lineData.pointWid * 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user