XCharts-Team / XCharts

A charting and data visualization library for Unity. Unity数据可视化图表插件。
https://xcharts-team.github.io
MIT License
3.31k stars 571 forks source link

Question: Tooltip, Corss, Indicator Label does not shown if Tooltip component is not turned off/on in inspector. #315

Closed HajiyevEl closed 5 months ago

HajiyevEl commented 7 months ago

I think something is wrong with 'AxisHandler.UpdatePointerValue()' or pointer value does not get updated after i manually change axis split number, depending on xDataZoom current data quantity.

Screenshot

![Screenshot 2024-04-11 195915](https://github.com/XCharts-Team/XCharts/assets/70325881/0928b590-7b1c-4931-87dd-f130a309e9db)

private void UpdateXAxisSplitNumber()
{
    var serie = chart.GetSerie(0);
    chart.GetDataZoomOfSerie(serie, out DataZoom xDataZoom, out DataZoom yDataZoom);

    var xAxis = chart.GetChartComponent<XAxis>(serie.xAxisIndex);

    xAxis.splitNumber = serie.GetDataList(xDataZoom).Count;
}

Also, please help me understand behaviour of indicator labels on axises when tooltip is set to Corss mode.

Problem is, when tooltip in Corss mode, indicator labels are hidden, even thought they are enabled on axises.

Indicator Labels Hidden (Play-mode)

![Screenshot 2024-04-12 115031](https://github.com/XCharts-Team/XCharts/assets/70325881/a2130c2b-2d61-4e1f-9f44-74121252dbe4) ![Screenshot 2024-04-12 114930](https://github.com/XCharts-Team/XCharts/assets/70325881/8366f18c-a23d-4ef6-8bf2-a48238a92e1e) ![Screenshot 2024-04-12 120512](https://github.com/XCharts-Team/XCharts/assets/70325881/ba0dcdf7-99c0-433a-9efd-317f7e618a6c)

But if i disable and than enable Tooltip (Play-mode), they are shown and cannot be disabled.

Indicator Shown (Play-mode)

![Screenshot 2024-04-12 120557](https://github.com/XCharts-Team/XCharts/assets/70325881/24767543-6c18-4c0e-ab95-661e7016f832) ![Screenshot 2024-04-12 120643](https://github.com/XCharts-Team/XCharts/assets/70325881/fea1c89f-54ba-444a-aeec-5a5e87cabf16) ![Screenshot 2024-04-12 120759](https://github.com/XCharts-Team/XCharts/assets/70325881/3484a958-620f-40a9-b32c-32660af7b047)

Somehow, when indicator labels shown/or hidden - enabling/or disabling Indicator labels (Play-mode) on axises does not change their active state. Is it intended? By the way, i downloaded Demo project, and seen there same behavior in candlestick charts. If you enable/disable tooltip component (Play-mode), indicator labels are shown and cannot be disabled.

@monitor1394

HajiyevEl commented 7 months ago

Well, i think indicator label with 'dynamic axis split number when zooming' problem solved. Changed some code in TooltipHandler.cs :

private void SetTooltipIndicatorLabel(Tooltip tooltip, Axis axis, ChartLabel label)
{
 ...
    if (axis.IsCategory())
    {
        // Old
        //var index = (int)axis.context.pointerValue;
        //var category = axis.GetData(index);
        //label.SetText(axis.indicatorLabel.GetFormatterContent(index, category));

        // Edited
        var index = (int)axis.context.pointerValue;
        var dataZoom = chart.GetDataZoomOfAxis(axis);
        var category = axis.GetData(index, dataZoom);
        label.SetText(axis.indicatorLabel.GetFormatterContent(index, category));
    }
...
}
Screenshot

![Screenshot 2024-04-12 163114](https://github.com/XCharts-Team/XCharts/assets/70325881/367654b6-25ef-44ac-8a10-b4c672de2b3d) ![Screenshot 2024-04-12 163148](https://github.com/XCharts-Team/XCharts/assets/70325881/1dc67c84-dd87-4140-b8e7-f3308309bd77)

But still, can't make Tooltip Indicator Labels show itself without turning on/off Tooltip component. Any ideas?

HajiyevEl commented 7 months ago

Also, it seems that Indicator labels and labels of axis cannot be disabled by just un-ticking active component, you must change at least some value inside component (for example sprite color) from default to custom, otherwise enabling/disabling component will not do anything. Tested on 'background' settings of indicatorLabel of axis.

HajiyevEl commented 7 months ago

Hi again! Same problem: can't make Tooltip Indicator Labels show itself without turning off/on Tooltip component in inspector. Please check this.

My Tooltip is set to Corss.

Tooltip Settings

![Screenshot 2024-04-27 130130](https://github.com/XCharts-Team/XCharts/assets/70325881/688ea626-34ca-49eb-aeeb-7134dacdc6a1)

When tooltip component is initialized, Tooltip type becomes 'Line', and updates to Corss only later. Also, 'm_LabelRoot' object is setting itself via 'ChartHelper.AddObject', but somewhere before code reaches 'UpdateTooltipIndicatorLabelText' - 'm_LabelRoot' again becomes null.

Screenshots

![Screenshot 2024-04-27 125100](https://github.com/XCharts-Team/XCharts/assets/70325881/52bdddcd-d951-43e0-bae6-bb9566147e87) ![Screenshot 2024-04-27 125750](https://github.com/XCharts-Team/XCharts/assets/70325881/930a6c23-0e3f-4f2f-8990-3e0cf04a68fe) ![Screenshot 2024-04-27 130018](https://github.com/XCharts-Team/XCharts/assets/70325881/778c8f3d-2b11-4050-87af-5193d99ab0f3)

I ended up adding label object manually. Even tho it's spaghetti code, tooltip indicator labels is shown without need for turning on/off Tooltip component in inspector. Can you please check in-depth about what causes this issue?

@monitor1394

monitor1394 commented 7 months ago

Hi again! Same problem: can't make Tooltip Indicator Labels show itself without turning off/on Tooltip component in inspector. Please check this.

My Tooltip is set to Corss.

Tooltip Settings Screenshot 2024-04-27 130130

When tooltip component is initialized, Tooltip type becomes 'Line', and updates to Corss only later. Also, 'm_LabelRoot' object is setting itself via 'ChartHelper.AddObject', but somewhere before code reaches 'UpdateTooltipIndicatorLabelText' - 'm_LabelRoot' again becomes null.

Screenshots Screenshot 2024-04-27 125100 Screenshot 2024-04-27 125750 Screenshot 2024-04-27 130018

I ended up adding label object manually. Even tho it's spaghetti code, tooltip indicator labels is shown without need for turning on/off Tooltip component in inspector. Can you please check in-depth about what causes this issue?

@monitor1394

I'm unable to replicate the issue you've described. Could you please provide detailed steps to reproduce it? Additionally, I attempted to set the type to 'Cross' both before and after execution, and in both cases, the operation performed normally.

HajiyevEl commented 7 months ago

I'm unable to replicate the issue you've described. Could you please provide detailed steps to reproduce it? Additionally, I attempted to set the type to 'Cross' both before and after execution, and in both cases, the operation performed normally.

You should try to instantiate prefab containing chart, because when i tried to replicate issue for you, i found out that even tho examples work fine, when i try to pack example script into prefab and instantiate it later, this issue with 'labels not showing' comes up (it seems that indicator line style color and other components will not be set properly either). So, it seems that if chart script exists in scene before play mode - all work as intended, but if you instantiate it later at runtime - issue comes up. Also, even tho i disabled/enabled Tooltip component in steps to replicate below, actually, disabling/enabling any of most of components will force labels to update (e.g. serie, axis, etc..)

I'm using XCharts version 3.10.2 in my project, but same issue exists in demo project.

Steps to replicate:

  1. Download Demo Project (https://github.com/XCharts-Team/XCharts-Demo)
  2. Enter Play Mode
  3. Select any chart with Corss type Tooltip (e.g. i selected Built-In Charts => Candlestick Chart => ShangHai Index)
    Select chart

Screenshot 2024-04-29 111343

  1. Check if chart shows indicator labels. Check if all settings is correct. If no => go next
    Check indicator labels and settings

Screenshot 2024-04-29 111411 Screenshot 2024-04-29 111524 Screenshot 2024-04-29 111549 Screenshot 2024-04-29 111606

  1. Disable Tooltip component in inspector
    Disable Tooltip

Screenshot 2024-04-29 111629

  1. Enable Tooltip component in inspector
    Enable Tooltip

Screenshot 2024-04-29 111653

  1. Check if indicator labels is shown
    Check indicator labels

Screenshot 2024-04-29 111717

monitor1394 commented 5 months ago

The issue has been fixed in version 3.11.0.