using UnityEngine;
using UnityEngine.UI;
using EasyChart.UGUI;
using EasyChart.UIToolKit;
namespace EasyChart.Samples
{
///
/// Simple example demonstrating how to use UGUIRuntimeJsonInjection or UIToolKitRuntimeJsonInjection
/// to update chart data via code. Attach this script to a GameObject with a Button.
///
public class JsonInjectionExample : MonoBehaviour
{
[Header("References (assign one)")]
[Tooltip("Reference to the UGUIRuntimeJsonInjection component on the chart (for UGUI)")]
[SerializeField] private UGUIRuntimeJsonInjection _uguiJsonInjection;
[Tooltip("Reference to the UIToolKitRuntimeJsonInjection component on the chart (for UI Toolkit)")]
[SerializeField] private UIToolKitRuntimeJsonInjection _uiToolkitJsonInjection;
[Tooltip("Optional: Button to trigger the update. If not set, will try to get from this GameObject.")]
[SerializeField] private Button _updateButton;
[Header("Sample JSON Data")]
[Tooltip("The JSON data to inject into the chart when button is clicked")]
[TextArea(10, 20)]
public string JsonData = @"{
""series"": [
{
""name"": ""Sales"",
""data"": [
{ ""x"": 0, ""value"": 120 },
{ ""x"": 1, ""value"": 200 },
{ ""x"": 2, ""value"": 150 },
{ ""x"": 3, ""value"": 80 },
{ ""x"": 4, ""value"": 170 }
]
}
]
}";
private void Start()
{
// Auto-get button if not assigned
if (_updateButton == null)
{
_updateButton = GetComponent