mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 02:10:16 +00:00
增加CandlestickChartK线图 #124
This commit is contained in:
@@ -317,6 +317,20 @@ namespace XCharts
|
||||
}
|
||||
return serieData;
|
||||
}
|
||||
public virtual SerieData AddData(int serieIndex, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
{
|
||||
var serieData = m_Series.AddData(serieIndex, open, close, lowest,heighest, dataName);
|
||||
if (serieData != null)
|
||||
{
|
||||
var serie = m_Series.GetSerie(serieIndex);
|
||||
if (SerieHelper.GetSerieLabel(serie, serieData).show)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
RefreshPainter(serie);
|
||||
}
|
||||
return serieData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update serie data by serie name.
|
||||
|
||||
36
Runtime/CandlestickChart.cs
Normal file
36
Runtime/CandlestickChart.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[AddComponentMenu("XCharts/CandlestickChart", 21)]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class CandlestickChart : CoordinateChart
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
title.text = "CandlestickChart";
|
||||
tooltip.type = Tooltip.Type.Corss;
|
||||
|
||||
RemoveData();
|
||||
var defaultDataCount = SerieTemplate.AddDefaultCandlestickSerie(this, "serie1");
|
||||
for (int i = 0; i < defaultDataCount; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Runtime/CandlestickChart.cs.meta
Normal file
11
Runtime/CandlestickChart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b64f0bb738cc4acfa72fff2c30212b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -60,6 +60,10 @@ namespace XCharts
|
||||
/// 水位图。
|
||||
/// </summary>
|
||||
Liquid,
|
||||
/// <summary>
|
||||
/// K线图。K线图的data至少包含四个数据:[open, close, lowest, highest]
|
||||
/// </summary>
|
||||
Candlestick,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1241,6 +1245,23 @@ namespace XCharts
|
||||
return serieData;
|
||||
}
|
||||
|
||||
public SerieData AddData(float open, float close, float lowest, float heighest, string dataName = null)
|
||||
{
|
||||
CheckMaxCache();
|
||||
var serieData = SerieDataPool.Get();
|
||||
serieData.data.Add(open);
|
||||
serieData.data.Add(close);
|
||||
serieData.data.Add(lowest);
|
||||
serieData.data.Add(heighest);
|
||||
serieData.name = dataName;
|
||||
serieData.index = m_Data.Count;
|
||||
m_Data.Add(serieData);
|
||||
m_ShowDataDimension = 4;
|
||||
SetVerticesDirty();
|
||||
CheckDataName(dataName);
|
||||
return serieData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将一组数据添加到系列中。
|
||||
/// 如果数据只有一个,默认添加到维度Y中。
|
||||
@@ -1277,6 +1298,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void CheckMaxCache()
|
||||
{
|
||||
if (m_MaxCache <= 0) return;
|
||||
|
||||
@@ -307,6 +307,36 @@ namespace XCharts
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加[open, close, lowest, highest]数据
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="open"></param>
|
||||
/// <param name="close"></param>
|
||||
/// <param name="lowest"></param>
|
||||
/// <param name="heighest"></param>
|
||||
/// <param name="dataName"></param>
|
||||
/// <returns></returns>
|
||||
public SerieData AddData(int index, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
return serie.AddData(open, close, lowest, heighest, dataName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SerieData AddData(string serieName, float open, float close, float lowest, float heighest, string dataName = null)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
return serie.AddData(open, close, lowest, heighest, dataName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一组数据到指定的系列中
|
||||
/// </summary>
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Show = false;
|
||||
[SerializeField] private Color32 m_Color;
|
||||
[SerializeField] private Color32 m_Color0;
|
||||
[SerializeField] private Color32 m_ToColor;
|
||||
[SerializeField] private Color32 m_ToColor2;
|
||||
[SerializeField] private Color32 m_BackgroundColor;
|
||||
@@ -46,6 +47,7 @@ namespace XCharts
|
||||
[SerializeField] private Type m_BorderType = Type.Solid;
|
||||
[SerializeField] private float m_BorderWidth = 0;
|
||||
[SerializeField] private Color32 m_BorderColor;
|
||||
[SerializeField] private Color32 m_BorderColor0;
|
||||
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
|
||||
[SerializeField] private string m_TooltipFormatter;
|
||||
[SerializeField] private string m_NumericFormatter = "";
|
||||
@@ -55,6 +57,7 @@ namespace XCharts
|
||||
{
|
||||
m_Show = false;
|
||||
m_Color = Color.clear;
|
||||
m_Color0 = Color.clear;
|
||||
m_ToColor = Color.clear;
|
||||
m_ToColor2 = Color.clear;
|
||||
m_BackgroundColor = Color.clear;
|
||||
@@ -64,6 +67,7 @@ namespace XCharts
|
||||
m_BorderType = Type.Solid;
|
||||
m_BorderWidth = 0;
|
||||
m_BorderColor = Color.clear;
|
||||
m_BorderColor0 = Color.clear;
|
||||
m_Opacity = 1;
|
||||
m_TooltipFormatter = null;
|
||||
m_NumericFormatter = "";
|
||||
@@ -95,6 +99,14 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据项颜色。
|
||||
/// </summary>
|
||||
public Color32 color0
|
||||
{
|
||||
get { return m_Color0; }
|
||||
set { if (PropertyUtil.SetColor(ref m_Color0, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gradient color1.
|
||||
/// 渐变色的颜色1。
|
||||
/// </summary>
|
||||
@@ -161,6 +173,14 @@ namespace XCharts
|
||||
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 边框的颜色。
|
||||
/// </summary>
|
||||
public Color32 borderColor0
|
||||
{
|
||||
get { return m_BorderColor0; }
|
||||
set { if (PropertyUtil.SetColor(ref m_BorderColor0, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 边框宽。
|
||||
/// </summary>
|
||||
public float borderWidth
|
||||
@@ -225,6 +245,41 @@ namespace XCharts
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
public Color32 GetColor0()
|
||||
{
|
||||
if (m_Opacity == 1 || m_Color0.a == 0) return m_Color0;
|
||||
var color = m_Color0;
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
public Color32 GetColor(Color32 defaultColor)
|
||||
{
|
||||
var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
|
||||
if (m_Opacity == 1 || color.a == 0) return color;
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
public Color32 GetColor0(Color32 defaultColor)
|
||||
{
|
||||
var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0;
|
||||
if (m_Opacity == 1 || color.a == 0) return color;
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
public Color32 GetBorderColor(Color32 defaultColor)
|
||||
{
|
||||
var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor;
|
||||
if (m_Opacity == 1 || color.a == 0) return color;
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
public Color32 GetBorderColor0(Color32 defaultColor)
|
||||
{
|
||||
var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0;
|
||||
if (m_Opacity == 1 || color.a == 0) return color;
|
||||
color.a = (byte)(color.a * m_Opacity);
|
||||
return color;
|
||||
}
|
||||
|
||||
public bool IsNeedGradient()
|
||||
{
|
||||
|
||||
@@ -121,12 +121,36 @@ namespace XCharts
|
||||
/// the maxinum value.
|
||||
/// 最大值。
|
||||
/// </summary>
|
||||
public float max { get { return m_Data.Max(); } }
|
||||
public float max
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
float temp = float.MinValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
if (m_Data[i] > temp) temp = m_Data[i];
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// the mininum value.
|
||||
/// 最小值。
|
||||
/// </summary>
|
||||
public float min { get { return m_Data.Min(); } }
|
||||
public float min
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Data.Count == 0) return 0;
|
||||
float temp = float.MaxValue;
|
||||
for (int i = 0; i < m_Data.Count; i++)
|
||||
{
|
||||
if (m_Data[i] < temp) temp = m_Data[i];
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 饼图数据项的开始角度(运行时自动计算)
|
||||
/// </summary>
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace XCharts
|
||||
[SerializeField] protected float m_ScatterSymbolSelectedSize;
|
||||
[SerializeField] protected float m_PieTooltipExtraRadius;
|
||||
[SerializeField] protected float m_PieSelectedOffset;
|
||||
[SerializeField] protected Color32 m_CandlestickColor = new Color32(194, 53, 49, 255);
|
||||
[SerializeField] protected Color32 m_CandlestickColor0 = new Color32(49, 70, 86, 255);
|
||||
[SerializeField] protected float m_CandlestickBorderWidth = 1;
|
||||
[SerializeField] protected Color32 m_CandlestickBorderColor = new Color32(194, 53, 49, 255);
|
||||
[SerializeField] protected Color32 m_CandlestickBorderColor0 = new Color32(49, 70, 86, 255);
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
@@ -67,6 +72,47 @@ namespace XCharts
|
||||
get { return m_PieSelectedOffset; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_PieSelectedOffset, value < 0 ? 0f : value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// K线图阳线(涨)填充色
|
||||
/// </summary>
|
||||
public Color32 candlestickColor
|
||||
{
|
||||
get { return m_CandlestickColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_CandlestickColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// K线图阴线(跌)填充色
|
||||
/// </summary>
|
||||
public Color32 candlestickColor0
|
||||
{
|
||||
get { return m_CandlestickColor0; }
|
||||
set { if (PropertyUtil.SetColor(ref m_CandlestickColor0, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// K线图阳线(跌)边框色
|
||||
/// </summary>
|
||||
public Color32 candlestickBorderColor
|
||||
{
|
||||
get { return m_CandlestickBorderColor; }
|
||||
set { if (PropertyUtil.SetColor(ref m_CandlestickBorderColor, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// K线图阴线(跌)边框色
|
||||
/// </summary>
|
||||
public Color32 candlestickBorderColor0
|
||||
{
|
||||
get { return m_CandlestickBorderColor0; }
|
||||
set { if (PropertyUtil.SetColor(ref m_CandlestickBorderColor0, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// K线图边框宽度
|
||||
/// </summary>
|
||||
public float candlestickBorderWidth
|
||||
{
|
||||
get { return m_CandlestickBorderWidth; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_CandlestickBorderWidth, value < 0 ? 0f : value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public void Copy(SerieTheme theme)
|
||||
{
|
||||
@@ -77,6 +123,11 @@ namespace XCharts
|
||||
m_ScatterSymbolSelectedSize = theme.scatterSymbolSelectedSize;
|
||||
m_PieTooltipExtraRadius = theme.pieTooltipExtraRadius;
|
||||
m_PieSelectedOffset = theme.pieSelectedOffset;
|
||||
m_CandlestickColor = theme.candlestickColor;
|
||||
m_CandlestickColor0 = theme.candlestickColor0;
|
||||
m_CandlestickBorderColor = theme.candlestickBorderColor;
|
||||
m_CandlestickBorderColor0 = theme.candlestickBorderColor0;
|
||||
m_CandlestickBorderWidth = theme.candlestickBorderWidth;
|
||||
}
|
||||
|
||||
public SerieTheme(Theme theme)
|
||||
@@ -88,6 +139,28 @@ namespace XCharts
|
||||
m_ScatterSymbolSelectedSize = XChartsSettings.serieScatterSymbolSelectedSize;
|
||||
m_PieTooltipExtraRadius = XChartsSettings.pieTooltipExtraRadius;
|
||||
m_PieSelectedOffset = XChartsSettings.pieSelectedOffset;
|
||||
m_CandlestickBorderWidth = XChartsSettings.serieCandlestickBorderWidth;
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Default:
|
||||
m_CandlestickColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
|
||||
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
|
||||
break;
|
||||
case Theme.Light:
|
||||
m_CandlestickColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
|
||||
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
|
||||
break;
|
||||
case Theme.Dark:
|
||||
m_CandlestickColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickColor0 = ColorUtil.GetColor("#314656");
|
||||
m_CandlestickBorderColor = ColorUtil.GetColor("#c23531");
|
||||
m_CandlestickBorderColor0 = ColorUtil.GetColor("#314656");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,9 @@ namespace XCharts
|
||||
case SerieType.Heatmap:
|
||||
DrawHeatmapSerie(vh, colorIndex, serie);
|
||||
break;
|
||||
case SerieType.Candlestick:
|
||||
DrawCandlestickSerie(vh, colorIndex, serie);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -846,7 +849,7 @@ namespace XCharts
|
||||
if (dataZoom != null && dataZoom.enable)
|
||||
{
|
||||
if (axis is XAxis) dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
else dataZoom.SetXAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
else dataZoom.SetYAxisIndexValueInfo(axisIndex, tempMinValue, tempMaxValue);
|
||||
}
|
||||
if (updateChart)
|
||||
{
|
||||
|
||||
@@ -587,7 +587,7 @@ namespace XCharts
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar)
|
||||
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick)
|
||||
{
|
||||
if (serie.barGap != 0)
|
||||
{
|
||||
@@ -625,7 +625,8 @@ namespace XCharts
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar && serie.show)
|
||||
if (!serie.show) continue;
|
||||
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serie.stack))
|
||||
{
|
||||
@@ -656,7 +657,8 @@ namespace XCharts
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
if (serie.type == SerieType.Bar && serie.show && now.stack.Equals(serie.stack))
|
||||
if ((serie.type == SerieType.Bar && serie.type == SerieType.Candlestick)
|
||||
&& serie.show && now.stack.Equals(serie.stack))
|
||||
{
|
||||
if (serie.barWidth > barWidth) barWidth = serie.barWidth;
|
||||
}
|
||||
|
||||
150
Runtime/Internal/CoordinateChart_DrawCandlestick.cs
Normal file
150
Runtime/Internal/CoordinateChart_DrawCandlestick.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class CoordinateChart
|
||||
{
|
||||
protected void DrawCandlestickSerie(VertexHelper vh, int colorIndex, Serie serie)
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
if (serie.animation.HasFadeOut()) return;
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
var yAxis = m_YAxes[serie.yAxisIndex];
|
||||
var xAxis = m_XAxes[serie.xAxisIndex];
|
||||
var grid = GetSerieGridOrDefault(serie);
|
||||
float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float offset = (categoryWidth - totalBarWidth) / 2;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float space = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth;
|
||||
int maxCount = serie.maxShow > 0
|
||||
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
|
||||
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
|
||||
var isAllBarEnd = true;
|
||||
var isYAxis = false;
|
||||
for (int i = serie.minShow; i < maxCount; i++)
|
||||
{
|
||||
var serieData = showData[i];
|
||||
if (serie.IsIgnoreValue(serieData.GetData(1)))
|
||||
{
|
||||
serie.dataPoints.Add(Vector3.zero);
|
||||
continue;
|
||||
}
|
||||
var highlight = (tooltip.show && tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
|
||||
var open = serieData.GetCurrData(0, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var close = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var lowest = serieData.GetCurrData(2, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var heighest = serieData.GetCurrData(3, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
|
||||
var isRise = close > open;
|
||||
var borderWidth = open == 0 ? 0f
|
||||
: (itemStyle.runtimeBorderWidth == 0 ? m_Theme.serie.candlestickBorderWidth
|
||||
: itemStyle.runtimeBorderWidth);
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
float pX = grid.runtimeX + i * categoryWidth;
|
||||
float zeroY = grid.runtimeY + yAxis.runtimeZeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
|
||||
float pY = zeroY;
|
||||
var barHig = 0f;
|
||||
var valueTotal = yMaxValue - yMinValue;
|
||||
var minCut = (yMinValue > 0 ? yMinValue : 0);
|
||||
if (valueTotal != 0)
|
||||
{
|
||||
barHig = (close - open) / valueTotal * grid.runtimeHeight;
|
||||
pY += (open - minCut) / valueTotal * grid.runtimeHeight;
|
||||
}
|
||||
serieData.runtimeStackHig = barHig;
|
||||
var isBarEnd = false;
|
||||
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
|
||||
if (!isBarEnd) isAllBarEnd = false;
|
||||
Vector3 plb, plt, prt, prb, top;
|
||||
|
||||
plb = new Vector3(pX + space + borderWidth, pY + borderWidth);
|
||||
plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth);
|
||||
prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth);
|
||||
prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth);
|
||||
top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
|
||||
if (serie.clip)
|
||||
{
|
||||
plb = ClampInGrid(grid, plb);
|
||||
plt = ClampInGrid(grid, plt);
|
||||
prt = ClampInGrid(grid, prt);
|
||||
prb = ClampInGrid(grid, prb);
|
||||
top = ClampInGrid(grid, top);
|
||||
}
|
||||
serie.dataPoints.Add(top);
|
||||
var areaColor = isRise
|
||||
? itemStyle.GetColor(m_Theme.serie.candlestickColor)
|
||||
: itemStyle.GetColor0(m_Theme.serie.candlestickColor0);
|
||||
var borderColor = isRise
|
||||
? itemStyle.GetBorderColor(m_Theme.serie.candlestickBorderColor)
|
||||
: itemStyle.GetBorderColor0(m_Theme.serie.candlestickBorderColor0);
|
||||
var itemWidth = Mathf.Abs(prt.x - plb.x);
|
||||
var itemHeight = Mathf.Abs(plt.y - prb.y);
|
||||
var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
|
||||
var lowPos = new Vector3(center.x, zeroY + (lowest - minCut) / valueTotal * grid.runtimeHeight);
|
||||
var heighPos = new Vector3(center.x, zeroY + (heighest - minCut) / valueTotal * grid.runtimeHeight);
|
||||
var openCenterPos = new Vector3(center.x, prb.y);
|
||||
var closeCenterPos = new Vector3(center.x, prt.y);
|
||||
if (barWidth > 2f * borderWidth)
|
||||
{
|
||||
if (itemWidth > 0 && itemHeight > 0)
|
||||
{
|
||||
if (ItemStyleHelper.IsNeedCorner(itemStyle))
|
||||
{
|
||||
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0,
|
||||
itemStyle.cornerRadius, isYAxis, 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor,
|
||||
serie.clip, grid);
|
||||
}
|
||||
UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,
|
||||
itemStyle.cornerRadius, isYAxis, 0.5f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawLine(vh, openCenterPos, closeCenterPos, Mathf.Max(borderWidth, barWidth / 2), borderColor);
|
||||
}
|
||||
if (isRise)
|
||||
{
|
||||
UGL.DrawLine(vh, openCenterPos, lowPos, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, closeCenterPos, heighPos, borderWidth, borderColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawLine(vh, closeCenterPos, lowPos, borderWidth, borderColor);
|
||||
UGL.DrawLine(vh, openCenterPos, heighPos, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
if (isAllBarEnd)
|
||||
{
|
||||
serie.animation.AllBarEnd();
|
||||
}
|
||||
if (dataChanging)
|
||||
{
|
||||
RefreshPainter(serie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/CoordinateChart_DrawCandlestick.cs.meta
Normal file
11
Runtime/Internal/CoordinateChart_DrawCandlestick.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c404a9bbfdf51409e808fb354c438ca2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -454,9 +454,19 @@ namespace XCharts
|
||||
var showData = serie.GetDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
var dataMin = data.min;
|
||||
var dataMax = data.max;
|
||||
if (dataMax > max) max = dataMax;
|
||||
if (dataMin < min) min = dataMin;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currData = data.GetData(yValue ? 1 : 0, inverse);
|
||||
if (currData > max) max = currData;
|
||||
if (currData < min) min = currData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,7 +498,15 @@ namespace XCharts
|
||||
{
|
||||
if (!_serieTotalValueForMinMax.ContainsKey(j))
|
||||
_serieTotalValueForMinMax[j] = 0;
|
||||
var currData = (yValue ? showData[j].GetData(1) : showData[j].GetData(0));
|
||||
var currData = 0f;
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
currData = showData[j].max;
|
||||
}
|
||||
else
|
||||
{
|
||||
currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
|
||||
}
|
||||
if (inverse) currData = -currData;
|
||||
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
|
||||
}
|
||||
|
||||
@@ -210,9 +210,25 @@ namespace XCharts
|
||||
{
|
||||
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
|
||||
ChartCached.FloatToStr(yValue, numericFormatter);
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>")
|
||||
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
|
||||
.Append(valueTxt);
|
||||
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (serie.type == SerieType.Candlestick)
|
||||
{
|
||||
sb.Append(key).Append(FormatterHelper.PH_NN);
|
||||
var data = serieData.data;
|
||||
var open = ChartCached.FloatToStr(data[0], numericFormatter);
|
||||
var close = ChartCached.FloatToStr(data[1], numericFormatter);
|
||||
var lowest = ChartCached.FloatToStr(data[2], numericFormatter);
|
||||
var heighest = ChartCached.FloatToStr(data[3], numericFormatter);
|
||||
sb.Append(" open: ").Append(open).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" close: ").Append(close).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" lowest: ").Append(lowest).Append(FormatterHelper.PH_NN);
|
||||
sb.Append(" heighest: ").Append(heighest).Append(FormatterHelper.PH_NN);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
|
||||
sb.Append(valueTxt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +240,7 @@ namespace XCharts
|
||||
{
|
||||
case SerieType.Line:
|
||||
case SerieType.Bar:
|
||||
case SerieType.Candlestick:
|
||||
InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace XCharts
|
||||
case SerieType.Liquid: AddDefaultLiquidSerie(chart, serieName); break;
|
||||
case SerieType.Gauge: AddDefaultGaugeSerie(chart, serieName); break;
|
||||
case SerieType.Ring: AddDefaultRingSerie(chart, serieName); break;
|
||||
case SerieType.Candlestick: AddDefaultCandlestickSerie(chart, serieName); break;
|
||||
default: Debug.LogError("AddDefaultSerie: not support serieType yet:" + serieType); break;
|
||||
}
|
||||
}
|
||||
@@ -168,5 +169,19 @@ namespace XCharts
|
||||
var max = 100;
|
||||
chart.AddData(serie.index, value, max, "data1");
|
||||
}
|
||||
public static int AddDefaultCandlestickSerie(BaseChart chart, string serieName)
|
||||
{
|
||||
var serie = chart.AddSerie(SerieType.Candlestick, serieName);
|
||||
var defaultDataCount = 5;
|
||||
for (int i = 0; i < defaultDataCount; i++)
|
||||
{
|
||||
var open = Random.Range(20, 60);
|
||||
var close = Random.Range(40, 90);
|
||||
var lowest = Random.Range(0, 50);
|
||||
var heighest = Random.Range(50, 100);
|
||||
chart.AddData(serie.index, open, close, lowest, heighest);
|
||||
}
|
||||
return defaultDataCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ namespace XCharts
|
||||
[SerializeField] [Range(0, 200)] private float m_SerieLineSymbolSelectedSize = 8f;
|
||||
[SerializeField] [Range(0, 200)] private float m_SerieScatterSymbolSize = 20f;
|
||||
[SerializeField] [Range(0, 200)] private float m_SerieScatterSymbolSelectedSize = 30f;
|
||||
[SerializeField] [Range(0, 10)] private float m_SerieCandlestickBorderWidth = 1f;
|
||||
|
||||
[SerializeField] private bool m_EditorBlockEnable = true;
|
||||
[SerializeField] private bool m_EditorShowAllListData = false;
|
||||
@@ -97,6 +98,7 @@ namespace XCharts
|
||||
public static float serieLineSymbolSelectedSize { get { return Instance.m_SerieLineSymbolSelectedSize; } }
|
||||
public static float serieScatterSymbolSize { get { return Instance.m_SerieScatterSymbolSize; } }
|
||||
public static float serieScatterSymbolSelectedSize { get { return Instance.m_SerieScatterSymbolSelectedSize; } }
|
||||
public static float serieCandlestickBorderWidth { get { return Instance.m_SerieCandlestickBorderWidth; } }
|
||||
#endregion
|
||||
|
||||
#region editor
|
||||
|
||||
Reference in New Issue
Block a user