mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 12:08:46 +00:00
增加用代码添加动态正弦曲线的示例
This commit is contained in:
61
Demo/Scripts/Demo11_AddSinCurve.cs
Normal file
61
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
Demo/Scripts/Demo11_AddSinCurve.cs.meta
Normal file
11
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:
|
||||||
178455
Demo/demo_xchart.unity
178455
Demo/demo_xchart.unity
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user