mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
增加GanttChart甘特图
This commit is contained in:
80
Examples/Runtime/Example100_Gantt_Category.cs
Normal file
80
Examples/Runtime/Example100_Gantt_Category.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Examples
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Example100_Gantt_Category : MonoBehaviour
|
||||
{
|
||||
private GanttChart chart;
|
||||
private float updateTime;
|
||||
public int dayCount = 10;
|
||||
public int taskCount = 5;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponent<GanttChart>();
|
||||
if (chart == null)
|
||||
{
|
||||
chart = gameObject.AddComponent<GanttChart>();
|
||||
}
|
||||
GenerateCategoryData();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
AddData();
|
||||
}
|
||||
}
|
||||
|
||||
void AddData()
|
||||
{
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "task-" + (i + 1);
|
||||
var startIndex = Random.Range(0, (int)(dayCount * 2.0f / 3));
|
||||
var endIndex = Random.Range(startIndex, dayCount);
|
||||
chart.UpdateData(0, i, 0, startIndex);
|
||||
chart.UpdateData(0, i, 1, endIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateCategoryData()
|
||||
{
|
||||
chart.RemoveData();
|
||||
|
||||
chart.grid.left = 100;
|
||||
chart.xAxis0.type = Axis.AxisType.Category;
|
||||
chart.xAxis0.boundaryGap = false;
|
||||
chart.xAxis0.splitNumber = dayCount;
|
||||
|
||||
chart.yAxis0.type = Axis.AxisType.Category;
|
||||
chart.yAxis0.boundaryGap = true;
|
||||
chart.yAxis0.splitNumber = 0;
|
||||
|
||||
for (int i = 0; i < dayCount; i++)
|
||||
{
|
||||
chart.AddXAxisData("day" + (i + 1));
|
||||
}
|
||||
|
||||
var serie = chart.AddSerie(SerieType.Gantt, "任务进度表");
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "task-" + (i + 1);
|
||||
var startIndex = Random.Range(0, (int)(dayCount * 2.0f / 3));
|
||||
var endIndex = Random.Range(startIndex, dayCount);
|
||||
chart.AddData(0, startIndex, endIndex, taskName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/Runtime/Example100_Gantt_Category.cs.meta
Normal file
11
Examples/Runtime/Example100_Gantt_Category.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c383c3eae67ed461693e18a807b2e599
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
Examples/Runtime/Example101_Gantt_Time.cs
Normal file
99
Examples/Runtime/Example101_Gantt_Time.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Examples
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Example101_Gantt_Time : MonoBehaviour
|
||||
{
|
||||
private GanttChart chart;
|
||||
private float updateTime;
|
||||
public int taskCount = 5;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponent<GanttChart>();
|
||||
if (chart == null)
|
||||
{
|
||||
chart = gameObject.AddComponent<GanttChart>();
|
||||
}
|
||||
GenerateTimeData();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
AddData();
|
||||
}
|
||||
}
|
||||
|
||||
void AddData()
|
||||
{
|
||||
chart.ClearData();
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "张三-任务-" + (i + 1);
|
||||
var nowTimestamp = DateTimeUtil.GetTimestamp();
|
||||
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
|
||||
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
|
||||
chart.AddData(0, startTimestamp, endTimestamp, taskName);
|
||||
}
|
||||
var serie2 = chart.AddSerie(SerieType.Gantt, "李四");
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "李四-任务-" + (i + 1);
|
||||
var nowTimestamp = DateTimeUtil.GetTimestamp();
|
||||
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
|
||||
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
|
||||
chart.AddData(1, startTimestamp, endTimestamp, taskName);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateTimeData()
|
||||
{
|
||||
chart.RemoveData();
|
||||
|
||||
chart.grid.left = 100;
|
||||
chart.xAxis0.type = Axis.AxisType.Time;
|
||||
chart.xAxis0.boundaryGap = false;
|
||||
chart.xAxis0.splitNumber = 5;
|
||||
|
||||
chart.xAxis0.axisLabel.numericFormatter = "HH:mm:ss";
|
||||
chart.xAxis0.axisLabel.formatter = "time:{value}";
|
||||
|
||||
chart.yAxis0.type = Axis.AxisType.Category;
|
||||
chart.yAxis0.boundaryGap = true;
|
||||
chart.yAxis0.splitNumber = 0;
|
||||
|
||||
|
||||
var serie1 = chart.AddSerie(SerieType.Gantt, "张三");
|
||||
serie1.label.show = true;
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "张三-任务-" + (i + 1);
|
||||
var nowTimestamp = DateTimeUtil.GetTimestamp();
|
||||
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
|
||||
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
|
||||
chart.AddData(0, startTimestamp, endTimestamp, taskName);
|
||||
}
|
||||
var serie2 = chart.AddSerie(SerieType.Gantt, "李四");
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
var taskName = "李四-任务-" + (i + 1);
|
||||
var nowTimestamp = DateTimeUtil.GetTimestamp();
|
||||
var startTimestamp = nowTimestamp + Random.Range(1, 6) * 3600 * 24;
|
||||
var endTimestamp = startTimestamp + Random.Range(1, 10) * 3600 * 24;
|
||||
chart.AddData(1, startTimestamp, endTimestamp, taskName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/Runtime/Example101_Gantt_Time.cs.meta
Normal file
11
Examples/Runtime/Example101_Gantt_Time.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d546ff7dfa6104a739c1accdb415ef54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -45,7 +45,6 @@ namespace XCharts.Examples
|
||||
chart.ClearData();
|
||||
|
||||
var xValue = System.DateTime.Now;
|
||||
var minute = 60 * 1000;
|
||||
var baseValue = Random.Range(0f, 1f) * 12000;
|
||||
var boxVals = new float[4];
|
||||
var dayRange = 12;
|
||||
|
||||
Reference in New Issue
Block a user