mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-29 20:58:47 +00:00
增加用代码添加动态正弦曲线的示例
This commit is contained in:
61
Assets/XCharts/Demo/Scripts/Demo11_AddSinCurve.cs
Normal file
61
Assets/XCharts/Demo/Scripts/Demo11_AddSinCurve.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/XCharts/Demo/Scripts/Demo11_AddSinCurve.cs.meta
Normal file
11
Assets/XCharts/Demo/Scripts/Demo11_AddSinCurve.cs.meta
Normal 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
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using System.Runtime.CompilerServices;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
@@ -170,6 +171,29 @@ namespace XCharts
|
|||||||
RefreshChart();
|
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>
|
/// <summary>
|
||||||
/// Update serie data by serie name.
|
/// Update serie data by serie name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -151,6 +151,16 @@ namespace XCharts
|
|||||||
return serie;
|
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)
|
public Serie AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
|
||||||
{
|
{
|
||||||
var serie = GetSerie(index);
|
var serie = GetSerie(index);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ QQ交流群:XCharts交流群(202030963)
|
|||||||
|
|
||||||
## 更新日志
|
## 更新日志
|
||||||
|
|
||||||
|
* (2019.07.19)增加用代码添加动态正弦曲线的示例`Demo11_AddSinCurve`
|
||||||
* (2019.07.19)优化`Legend`的显示和控制
|
* (2019.07.19)优化`Legend`的显示和控制
|
||||||
* (2019.07.18)优化抗锯齿,曲线更平滑
|
* (2019.07.18)优化抗锯齿,曲线更平滑
|
||||||
* (2019.07.18)增加`Tooltip`指示器类型,优化显示控制
|
* (2019.07.18)增加`Tooltip`指示器类型,优化显示控制
|
||||||
@@ -69,6 +70,7 @@ QQ交流群:XCharts交流群(202030963)
|
|||||||
13. 大数据+区域缩放
|
13. 大数据+区域缩放
|
||||||
14. 双坐标轴
|
14. 双坐标轴
|
||||||
15. 笛卡尔坐标系(XY都为数值轴)
|
15. 笛卡尔坐标系(XY都为数值轴)
|
||||||
|
16. 用代码添加动态的正弦曲线
|
||||||
|
|
||||||
### 柱状图
|
### 柱状图
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user