Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

两个图表赋不同值时会产生错误 #239

Closed
shangchengwen opened this issue Dec 29, 2022 · 3 comments
Closed

两个图表赋不同值时会产生错误 #239

shangchengwen opened this issue Dec 29, 2022 · 3 comments

Comments

@shangchengwen
Copy link

当给两个图表赋不同值时会产生错误
第二张的图表的值会显示在第一张图表上
运行时查看数据是正确的

chart_distance = obj_distance.GetComponent<ScatterChart>();
chart_angle = obj_angle.GetComponent<ScatterChart>();
serie_angle = chart_angle.GetSerie("serie0");
serie_distance = chart_distance.GetSerie("serie0");

目前解决办法

1.两个图表要有一个初始数据,并且数据不能为0,0
2.并且代码中不能用CleanData

@monitor1394
Copy link
Collaborator

不太明白是什么意思

@monitor1394
Copy link
Collaborator

两个图表之间基本没有关联,我觉得不应该出现这种问题。
具体的话,可以发一下相关代码和效果图一起排查一下。

@shangchengwen
Copy link
Author

之前没仔细找,应该是DataZoom组件导致的

创建两个散点图,用下面的脚本
没有DataZoom组件的时候正常,一个图数据增,一个图数据减
两个散点图都添加DataZoom组件后会互相影响

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

public class XchartTest : MonoBehaviour
{
public GameObject obj_distance;
public GameObject obj_angle;

private ScatterChart chart_distance;
private ScatterChart chart_angle;

private Serie serie_distance;
private Serie serie_angle;

public int data_index = 0;
int data_index_max = 3000;

void Start()
{
    ChartInit();
}


int int_angle = 0;
int int_distance = 0;
int time_in = 0;
private void Update() {
    if(time_in++%100!=0){
        return;
    }
    int_angle+=5;
    int_distance-=3;
    if (data_index == 0)
        {
            if (serie_angle != null)
            {
                serie_angle.UpdateXYData(data_index, data_index, int_angle);
            }

            if (serie_distance != null)
            {
                serie_distance.UpdateXYData(data_index, data_index, int_distance);
            }

        }
        else if (data_index < data_index_max)
        {
            if (serie_angle != null)
                serie_angle.AddXYData(data_index, int_angle);
            if (serie_distance != null)
                serie_distance.AddXYData(data_index, int_distance);
        }
        else
        {
            if (serie_angle != null)
            {
                serie_angle.UpdateXYData(data_index % data_index_max, data_index, int_angle);
            }
            if (serie_distance != null)
            {
                serie_distance.UpdateXYData(data_index % data_index_max, data_index, int_distance);
            }

        }
        data_index++;
}

private void ChartInit()
{
    chart_distance = obj_distance.GetComponent<ScatterChart>();
    chart_angle = obj_angle.GetComponent<ScatterChart>();
    SetAxis(chart_distance);
    SetAxis(chart_angle);
    serie_angle = chart_angle.GetSerie("serie0");
    serie_distance = chart_distance.GetSerie("serie0");
    ClearData();
}

public void ClearData()
{
    serie_angle.ClearData();
    serie_distance.ClearData();
}

private void SetAxis(ScatterChart chart)
{
    XAxis xAxis = chart.GetOrAddChartComponent<XAxis>();
    xAxis.minMaxType = XAxis.AxisMinMaxType.MinMax;
    YAxis yAxis = chart.GetOrAddChartComponent<YAxis>();
    yAxis.minMaxType = YAxis.AxisMinMaxType.MinMax;
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants