diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index 03fbf040..e9ee5cd8 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -779,7 +779,7 @@ Bar chart shows different data through the height of a bar, which is used in rec |HasChartComponent<T>()||public bool HasChartComponent<T>()| |HasSerie()||public bool HasSerie(Type type)| |HasSerie<T>()||public bool HasSerie<T>() where T : Serie| -|Init()||public void Init(bool defaultChart = true) { }| +|Init()||public void Init(bool defaultChart = true)| |InitAxisRuntimeData()||public virtual void InitAxisRuntimeData(Axis axis) { }| |InsertSerie()||public void InsertSerie(Serie serie, int index = -1, bool addToHead = false)| |InsertSerie<T>()||public T InsertSerie<T>(int index, string serieName = null, bool show = true) where T : Serie| diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index ffa4bcfc..cd862f3d 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -779,7 +779,7 @@ slug: /api |HasChartComponent<T>()||public bool HasChartComponent<T>()| |HasSerie()||public bool HasSerie(Type type)| |HasSerie<T>()||public bool HasSerie<T>() where T : Serie| -|Init()||public void Init(bool defaultChart = true) { }| +|Init()||public void Init(bool defaultChart = true)| |InitAxisRuntimeData()||public virtual void InitAxisRuntimeData(Axis axis) { }| |InsertSerie()||public void InsertSerie(Serie serie, int index = -1, bool addToHead = false)| |InsertSerie<T>()||public T InsertSerie<T>(int index, string serieName = null, bool show = true) where T : Serie| diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index b0501c50..f629f353 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -72,7 +72,6 @@ slug: /changelog * (2024.01.18) 修复`Animation`的`type`代码动态修改无效的问题 * (2024.01.13) 增加`Chart`的更多快捷创建图表菜单 -* (2024.01.12) 屏蔽`Chart`的`Init()`接口,动态创建图表不再需要调用 * (2024.01.09) 增加`Background`的`borderStyle`,给图表默认设置圆角 * (2024.01.07) 修复`Tooltop`的第一个`ContentLabelStyle`设置`color`无效的问题 * (2024.01.01) 增加`BorderStyle`边框样式 diff --git a/Examples/Example03_ChartAnimation.cs b/Examples/Example03_ChartAnimation.cs index f02e478b..708eea10 100644 --- a/Examples/Example03_ChartAnimation.cs +++ b/Examples/Example03_ChartAnimation.cs @@ -15,6 +15,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent(); + chart.Init(); } var serie = chart.GetSerie(0); serie.animation.enable = true; diff --git a/Examples/Example10_LineChart.cs b/Examples/Example10_LineChart.cs index 2dabb5fb..1814d641 100644 --- a/Examples/Example10_LineChart.cs +++ b/Examples/Example10_LineChart.cs @@ -40,7 +40,10 @@ namespace XCharts.Example IEnumerator AddSimpleLine() { chart = gameObject.GetComponent(); - if (chart == null) chart = gameObject.AddComponent(); + if (chart == null){ + chart = gameObject.AddComponent(); + chart.Init(); + } chart.GetChartComponent().text = "LineChart - 折线图"; chart.GetChartComponent<Title>().subText = "普通折线图"; diff --git a/Examples/Example11_AddSinCurve.cs b/Examples/Example11_AddSinCurve.cs index e54efba0..dac854c6 100644 --- a/Examples/Example11_AddSinCurve.cs +++ b/Examples/Example11_AddSinCurve.cs @@ -16,6 +16,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<LineChart>(); + chart.Init(); } chart.EnsureChartComponent<Title>().show = true; chart.EnsureChartComponent<Title>().text = "Sin Curve"; diff --git a/Examples/Example13_LineSimple.cs b/Examples/Example13_LineSimple.cs index 5e4f24fe..0a78a417 100644 --- a/Examples/Example13_LineSimple.cs +++ b/Examples/Example13_LineSimple.cs @@ -29,7 +29,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<LineChart>(); - chart.SetSize(580, 300); + chart.Init(); } chart.EnsureChartComponent<Title>().show = true; chart.EnsureChartComponent<Title>().text = "Line Simple"; diff --git a/Examples/Example20_BarChart.cs b/Examples/Example20_BarChart.cs index 70149d6a..fcebaa82 100644 --- a/Examples/Example20_BarChart.cs +++ b/Examples/Example20_BarChart.cs @@ -38,7 +38,11 @@ namespace XCharts.Example IEnumerator AddSimpleBar() { chart = gameObject.GetComponent<BarChart>(); - if (chart == null) chart = gameObject.AddComponent<BarChart>(); + if (chart == null) + { + chart = gameObject.AddComponent<BarChart>(); + chart.Init(); + } chart.EnsureChartComponent<Title>().text = "BarChart - 柱状图"; chart.EnsureChartComponent<Title>().subText = "普通柱状图"; diff --git a/Examples/Example30_PieChart.cs b/Examples/Example30_PieChart.cs index 4d90c9c8..ae80b608 100644 --- a/Examples/Example30_PieChart.cs +++ b/Examples/Example30_PieChart.cs @@ -38,7 +38,11 @@ namespace XCharts.Example IEnumerator PieAdd() { chart = gameObject.GetComponent<PieChart>(); - if (chart == null) chart = gameObject.AddComponent<PieChart>(); + if (chart == null) + { + chart = gameObject.AddComponent<PieChart>(); + chart.Init(); + } yield return null; chart.GetChartComponent<Title>().text = "PieChart - 饼图"; chart.GetChartComponent<Title>().subText = "基础饼图"; diff --git a/Examples/Example31_PieUpdateName.cs b/Examples/Example31_PieUpdateName.cs index 2c79e5d9..d4449cea 100644 --- a/Examples/Example31_PieUpdateName.cs +++ b/Examples/Example31_PieUpdateName.cs @@ -17,6 +17,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<PieChart>(); + chart.Init(); } var serieIndex = 0; var serie = chart.GetSerie(serieIndex); diff --git a/Examples/Example40_Radar.cs b/Examples/Example40_Radar.cs index f33dc258..fc9dfaf1 100644 --- a/Examples/Example40_Radar.cs +++ b/Examples/Example40_Radar.cs @@ -40,7 +40,11 @@ namespace XCharts.Example IEnumerator RadarAdd() { chart = gameObject.GetComponent<RadarChart>(); - if (chart == null) chart = gameObject.AddComponent<RadarChart>(); + if (chart == null) + { + chart = gameObject.AddComponent<RadarChart>(); + chart.Init(); + } chart.RemoveChartComponents<RadarCoord>(); chart.RemoveData(); diff --git a/Examples/Example41_RadarUpdate.cs b/Examples/Example41_RadarUpdate.cs index 7ed98895..03d23db5 100644 --- a/Examples/Example41_RadarUpdate.cs +++ b/Examples/Example41_RadarUpdate.cs @@ -19,6 +19,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<RadarChart>(); + chart.Init(); } } diff --git a/Examples/Example60_Heatmap.cs b/Examples/Example60_Heatmap.cs index 263b6382..3c06639a 100644 --- a/Examples/Example60_Heatmap.cs +++ b/Examples/Example60_Heatmap.cs @@ -16,6 +16,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<HeatmapChart>(); + chart.Init(); } chart.GetChartComponent<Title>().text = "HeatmapChart"; chart.GetChartComponent<Tooltip>().type = Tooltip.Type.None; diff --git a/Examples/Example80_Polar.cs b/Examples/Example80_Polar.cs index e5e202c5..cc6a99c0 100644 --- a/Examples/Example80_Polar.cs +++ b/Examples/Example80_Polar.cs @@ -18,6 +18,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<BaseChart>(); + chart.Init(); } chart.EnsureChartComponent<PolarCoord>(); } diff --git a/Examples/Example90_Candlestick.cs b/Examples/Example90_Candlestick.cs index 736925c5..acde88de 100644 --- a/Examples/Example90_Candlestick.cs +++ b/Examples/Example90_Candlestick.cs @@ -19,6 +19,7 @@ namespace XCharts.Example if (chart == null) { chart = gameObject.AddComponent<CandlestickChart>(); + chart.Init(); } AddData(); } diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 1bcabee3..9da4fdf2 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -166,8 +166,18 @@ namespace XCharts.Runtime /// </summary> public Action<Legend, int, string> onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } } - [Obsolete("No need to call Init() anymore.", true)] - public void Init(bool defaultChart = true) { } + public void Init(bool defaultChart = true) + { + if (defaultChart) + { + OnInit(); + DefaultChart(); + } + else + { + OnBeforeSerialize(); + } + } /// <summary> /// Redraw chart in next frame. diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 2cf33bbb..e8353ce5 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -136,7 +136,6 @@ namespace XCharts.Runtime m_Settings = Settings.DefaultSettings; CheckTheme(true); base.Awake(); - CheckChartInit(); InitComponentHandlers(); InitSerieHandlers(); AnimationReset();