XCharts - the best free open source chart plug-in for Unity! (2) Advanced usage - super powerful XCharts combined with code

Basic introduction to the previous article: XCharts - the best free open source chart plug-in for Unity! (1) Basic introduction

This issue introduces the advanced usage of XCharts - super powerful XCharts combined with code

Only focus!!!

Table of contents

1. Legend (group classification prompts)

2. Percent type display

3. Corresponding data display

4. Special data types (definitely determined next time)


1. Legend (group classification tips)

However, we need to add this legend ourselves . The one introduced in the previous article is built-in.

When you use it, the data group classification will appear

 

 As for the small categories, I have already talked about them in the previous article . Here I will talk about the key points.

2. Percent type display

 
Here you can see that the data on the Y-axis is displayed in percentage type, so how is this done? Some brothers should have an idea. All we need to do is to add data (0, 20, 40... ) just add a percent sign after it, so you need to use the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts.Runtime;

public class MyChart : MonoBehaviour
{
    public LineChart lineChart;
    private void Start()
    {
        lineChart.EnsureChartComponent<YAxis>().axisLabel.formatter = "{value}%";
    }
}

The EnsureComponent<> method here is analogous to GetComponent<> , which is to get the component YAxis, that is, to get the Y axis.

 Then... formatter= "{value}%"   is a format function, which means replacing it with the form of " data+% ". You can learn about it.

Note: using XCharts.Runtime; must be added. If it cannot be used or an error is reported, try again.

3. Corresponding data display

What you can see is that each of my data will have data display corresponding to it . So how is it achieved?

This uses a hidden component that cannot be found in the visualization window. Let’s start with the code.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts.Runtime;
 
public class MyChart : MonoBehaviour
{
    public LineChart lineChart;
    private void Start()
    {
        lineChart.EnsureChartComponent<YAxis>().axisLabel.formatter = "{value}%";
        for (int i = 0; i < lineChart.series.Length; i++)
        {
                lineChart.series[0].EnsureComponent<LabelStyle>();
                lineChart.series[0].label.offset = new Vector3(0, 20, 0);
        }
    }
}

Before we talked about the EnsureComponent<> method is analogous to GetComponent<> , but it is an analogy and not the same.

Because the EnsureComponent<> method will be added for you if it does not exist , so this is to add a component (in the serie)

After running, there is an additional component.

 once i turn off

 

4. Special data types (definitely determined next time)

......

Guess you like

Origin blog.csdn.net/2201_75516689/article/details/132023440