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

Two charts on one page, only one updates on data change. #445

Open
mikend opened this issue Apr 18, 2024 · 5 comments
Open

Two charts on one page, only one updates on data change. #445

mikend opened this issue Apr 18, 2024 · 5 comments

Comments

@mikend
Copy link

mikend commented Apr 18, 2024

I have two charts on one page. When I change the data for both charts, only the first one get updated. If I change the order of them, it's still the first one that changes. I've tried to call RenderAsync, but it throws a null reference exception...

@joadan
Copy link
Member

joadan commented Apr 18, 2024

Hi,

Make sure you don't share the options object...

@mikend
Copy link
Author

mikend commented Apr 18, 2024

Not sharing anything.

@joadan
Copy link
Member

joadan commented Apr 18, 2024

Ok.. can you share some code so we can have a look?

@mikend
Copy link
Author

mikend commented Apr 18, 2024

Page:

<EditForm>
  <button @onclick="View">View</button>
</EditForm>
<Component1 Data=@data1 />
<Component2 Data=@data2 />

@code {
  private List<MyType>? data1;
  private List<MyType>? data2;

  protected override async Task OnInitializedAsync ()
  {
    await View();
  }

  private async Task View ()
  {
    await ViewChart1();
    await ViewChart2();
  }

  private async Task ViewChart1 ()
  {
    data1 = null;
    data1 = await dataService.GetData1();
  }

  private async Task ViewChart2 ()
  {
    data2 = null;
    data2 = await dataService.GetData2();
  }
}


Component 1:

<div>
  @if (Data is not null) {
    <ApexChart TItem="MyType" Title="">
      <ApexPointSeries
        TItem="MyType"
        Items="Data"
        Name=""
        SeriesType="SeriesType.Pie"
        XValue='e => e.Name"'
        YValue="e => e.Count"
      />
    </ApexChart>
  }
</div>

@code {
  [Parameter] public List<MyType>? Data {get; set;}

  private void OnDataChanged ()
  {
  }
}

Component 2:

<div>
  @if (Data is not null) {
    <ApexChart TItem="MyType" Title="">
      <ApexPointSeries
        TItem="MyType"
        Items="Data"
        Name=""
        SeriesType="SeriesType.Line"
        XValue="e => e.Date"
        YValue="e => e.Count"
      />
    </ApexChart>
  }
</div>

@code {
  [Parameter] public List<MyType>? Data {get; set;}

  private void OnDataChanged ()
  {
  }
}

@mikend mikend changed the title Two charts on one page, only one updates in data change. Two charts on one page, only one updates on data change. Apr 18, 2024
@joadan
Copy link
Member

joadan commented Apr 27, 2024

Hi

I'm sorry it's hard when I can't run the sample code.

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