增加南丁格尔玫瑰图

This commit is contained in:
monitor1394
2018-09-23 13:32:46 +08:00
parent ba29fb86b4
commit 6f2a6c6bee
7 changed files with 1551 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ namespace xcharts
{ {
public float insideRadius = 0f; public float insideRadius = 0f;
public float outsideRadius = 80f; public float outsideRadius = 80f;
public bool outsideRadiusDynamic = false;
public float space; public float space;
public float left; public float left;
public float right; public float right;
@@ -60,14 +61,19 @@ namespace xcharts
float totalDegree = 360; float totalDegree = 360;
float startDegree = 0; float startDegree = 0;
float dataTotal = GetDataTotal(); float dataTotal = GetDataTotal();
float dataMax = GetDataMax();
for (int i = 0; i < pieInfo.dataList.Count; i++) for (int i = 0; i < pieInfo.dataList.Count; i++)
{ {
if (!legend.IsShowSeries(i)) continue; if (!legend.IsShowSeries(i)) continue;
float value = pieInfo.dataList[i].value; float value = pieInfo.dataList[i].value;
float degree = totalDegree * value / dataTotal; float degree = totalDegree * value / dataTotal;
float toDegree = startDegree + degree; float toDegree = startDegree + degree;
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius, pieRadius,
startDegree, toDegree, legend.GetColor(i)); float outSideRadius = pieInfo.outsideRadiusDynamic ?
pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
pieRadius;
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius,
outSideRadius,startDegree, toDegree, legend.GetColor(i));
startDegree = toDegree; startDegree = toDegree;
} }
} }
@@ -91,6 +97,19 @@ namespace xcharts
return total; return total;
} }
private float GetDataMax()
{
float max = 0;
for(int i = 0; i < pieInfo.dataList.Count; i++)
{
if(legend.IsShowSeries(i) && pieInfo.dataList[i].value > max)
{
max = pieInfo.dataList[i].value;
}
}
return max;
}
private void UpdatePieCenter() private void UpdatePieCenter()
{ {
float diffX = chartWid - pieInfo.left - pieInfo.right; float diffX = chartWid - pieInfo.left - pieInfo.right;

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,10 @@
# XChart # XChart
A Simple UGUI Charting Library for Unity A Simple UGUI Charting Library for Unity
![效果图](demo.png) # 效果图
1.折线图
![折线图](demo_line.png)
2.柱形图
![柱形图](demo_bar.png)
3.饼图
![饼图](demo_pie.png)

BIN
demo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

BIN
demo_bar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
demo_line.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
demo_pie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB