diff --git a/Examples/Example05_DynamicChart.cs b/Examples/Example05_DynamicChart.cs index 5818517c..234ed595 100644 --- a/Examples/Example05_DynamicChart.cs +++ b/Examples/Example05_DynamicChart.cs @@ -42,7 +42,6 @@ namespace XCharts.Example { var chartObject = CreateChartObject(chartName); var chart = chartObject.AddComponent(); - chart.Init(); chart.SetSize(580, 300); chart.EnsureChartComponent().show = true; @@ -64,7 +63,6 @@ namespace XCharts.Example { var chartObject = CreateChartObject(chartName); var chart = chartObject.AddComponent<PieChart>(); - chart.Init(); chart.SetSize(580, 300); chart.EnsureChartComponent<Title>().show = true; diff --git a/Examples/Example13_LineSimple.cs b/Examples/Example13_LineSimple.cs index 72d8ebe4..5e4f24fe 100644 --- a/Examples/Example13_LineSimple.cs +++ b/Examples/Example13_LineSimple.cs @@ -25,11 +25,10 @@ namespace XCharts.Example void AddData() { - var chart = gameObject.GetComponent<SimplifiedLineChart>(); + var chart = gameObject.GetComponent<LineChart>(); if (chart == null) { - chart = gameObject.AddComponent<SimplifiedLineChart>(); - chart.Init(); + chart = gameObject.AddComponent<LineChart>(); chart.SetSize(580, 300); } chart.EnsureChartComponent<Title>().show = true; @@ -49,9 +48,9 @@ namespace XCharts.Example xAxis.boundaryGap = true; chart.RemoveData(); - chart.AddSerie<SimplifiedLine>(); - chart.AddSerie<SimplifiedLine>(); - for (int i = 0; i < 200; i++) + chart.AddSerie<Line>(); + chart.AddSerie<Line>(); + for (int i = 0; i < 20; i++) { chart.AddXAxisData("x" + i); chart.AddData(0, Random.Range(10, 20)); diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 7952d057..1bcabee3 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -165,19 +165,10 @@ namespace XCharts.Runtime /// ||鼠标退出图例回调。参数:legendIndex, legendName /// </summary> public Action<Legend, int, string> onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } } - public void Init(bool defaultChart = true) - { - if (defaultChart) - { - OnInit(); - DefaultChart(); - m_DefaultChartInited = true; - } - else - { - OnBeforeSerialize(); - } - } + + [Obsolete("No need to call Init() anymore.", true)] + public void Init(bool defaultChart = true) { } + /// <summary> /// Redraw chart in next frame. /// ||在下一帧刷新整个图表。 diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 3f7bf83d..2cf33bbb 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -19,7 +19,7 @@ namespace XCharts.Runtime [SerializeField] protected ThemeStyle m_Theme = new ThemeStyle(); [SerializeField] protected Settings m_Settings; [SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo(); - [SerializeField] protected bool m_DefaultChartInited = false; + [SerializeField] protected bool m_ChartInited = false; #pragma warning disable 0414 [SerializeField][ListForComponent(typeof(AngleAxis))] private List<AngleAxis> m_AngleAxes = new List<AngleAxis>(); @@ -136,6 +136,7 @@ namespace XCharts.Runtime m_Settings = Settings.DefaultSettings; CheckTheme(true); base.Awake(); + CheckChartInit(); InitComponentHandlers(); InitSerieHandlers(); AnimationReset(); @@ -171,17 +172,26 @@ namespace XCharts.Runtime rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight); } ChartHelper.HideAllObject(transform); + m_ChartInited = true; if (m_OnInit != null) m_OnInit(); } + protected void CheckChartInit() + { + if (!m_ChartInited) + { + OnInit(); + DefaultChart(); + } + } + #if UNITY_EDITOR protected override void Reset() { base.Reset(); OnInit(); DefaultChart(); - m_DefaultChartInited = true; Awake(); }