增加用代码添加动态正弦曲线的示例

This commit is contained in:
monitor1394
2019-07-19 23:17:06 +08:00
parent 3c17d7763b
commit 9f93d71279
6 changed files with 131237 additions and 47328 deletions

View File

@@ -0,0 +1,61 @@
using UnityEngine;
using XCharts;
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo11_AddSinCurve : MonoBehaviour
{
private float time;
public int angle;
private LineChart chart;
void Awake()
{
chart = gameObject.GetComponent<LineChart>();
if (chart != null)
{
GameObject.DestroyImmediate(chart);
}
chart = gameObject.AddComponent<LineChart>();
chart.title.show = true;
chart.title.text = "Sin Curve";
chart.tooltip.show = true;
chart.legend.show = false;
chart.xAxises[0].show = true;
chart.xAxises[1].show = false;
chart.yAxises[0].show = true;
chart.yAxises[1].show = false;
chart.xAxises[0].type = Axis.AxisType.Value;
chart.yAxises[0].type = Axis.AxisType.Value;
chart.xAxises[0].boundaryGap = false;
chart.maxCacheDataNumber = 0;
chart.line.point = false;
chart.line.step = false;
chart.line.smooth = false;
chart.line.area = false;
chart.RemoveData();
chart.AddSerie("test", SerieType.Line);
for (angle = 0; angle < 1080; angle++)
{
float xvalue = Mathf.PI / 180 * angle;
float yvalue = Mathf.Sin(xvalue);
chart.AddXYData(0, xvalue, yvalue);
}
}
void Update()
{
if(angle > 3000) return;
angle++;
float xvalue = Mathf.PI / 180 * angle;
float yvalue = Mathf.Sin(xvalue);
chart.AddXYData(0, xvalue, yvalue);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee2ff4f81f1754f9e8e1df797df8c201
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
@@ -170,6 +171,29 @@ namespace XCharts
RefreshChart();
}
/// <summary>
/// Add a (x,y) data to serie
/// </summary>
/// <param name="serieName">the name of serie</param>
/// <param name="xValue">x data</param>
/// <param name="yValue">y data</param>
public virtual void AddXYData(string serieName, float xValue, float yValue)
{
m_Series.AddXYData(serieName, xValue, yValue, m_MaxCacheDataNumber);
RefreshChart();
}
/// <summary>
/// Add a (x,y) data to serie
/// </summary>
/// <param name="serieIndex">the index of serie</param>
/// <param name="xValue">x data</param>
/// <param name="yValue">y data</param>
public virtual void AddXYData(int serieIndex, float xValue, float yValue)
{
m_Series.AddXYData(serieIndex, xValue, yValue, m_MaxCacheDataNumber);
RefreshChart();
}
/// <summary>
/// Update serie data by serie name.
/// </summary>

View File

@@ -151,6 +151,16 @@ namespace XCharts
return serie;
}
public Serie AddXYData(string serieName, float xValue, float yValue, int maxDataNumber = 0)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.AddXYData(xValue, yValue, maxDataNumber);
}
return serie;
}
public Serie AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
{
var serie = GetSerie(index);

View File

@@ -23,6 +23,7 @@ QQ交流群XCharts交流群202030963
## 更新日志
* 2019.07.19)增加用代码添加动态正弦曲线的示例`Demo11_AddSinCurve`
* 2019.07.19)优化`Legend`的显示和控制
* 2019.07.18)优化抗锯齿,曲线更平滑
* 2019.07.18)增加`Tooltip`指示器类型,优化显示控制
@@ -69,6 +70,7 @@ QQ交流群XCharts交流群202030963
13. 大数据+区域缩放
14. 双坐标轴
15. 笛卡尔坐标系XY都为数值轴
16. 用代码添加动态的正弦曲线
### 柱状图