0

Below setExtremes works fine for initial chart. But when I switch pages and reopen chart again or open new chart(new json file), below setExtremes stops working and does not update min max anymore. Any suggestion why this would happen.

yAxis[BtnID].setExtremes(val1, val2);

The only way I could make it work is by force reloading my app, then it works when I reopen chart or open new chart(new json file). Below is my actual code. There is no problem with json data. I am getting BtnID, val1, val2 values fine, only setExtremes does not work (works first time but not after) .

Button click on navbar as shown below, opens a modal, where user enters val1 and val2. Which s then sent to index.js.

Navbar.razor:

 <button @ref="_btn1Ref" id="0" @onclick=OpenDialog1>dialog1</button>
 <button @ref="_btn2Ref" id="1" @onclick=OpenDialog2>dialog2</button>
                          
@code{

private MyData model1 = new MyData { val1= 0, val2= 0 };
private MyData model2 = new MyData { val1= 0, val2= 0 };

private IModalDialog? modalDialog;

private async Task OpenDialog1()
{
    var request = new ModalRequest { InData = this.model1 };
    if (this.modalDialog is not null)
        await modalDialog.ShowAsync<MyForm>(request);      
    await JSRuntime.InvokeVoidAsync("getValues", this.model1.val1, this.model1.val2, _btn1Ref);
}
    ...

Index.razor:

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    var fileName = @fileNameFromLandingPage;       
    await JSRuntime.InvokeVoidAsync("CreateChart", fileName);
    
}

Index.js:

 function CreateChart(fileName) {  
   $.getJSON(fileName, function (data) {
       
       var chart = Highcharts.chart('container', {  ....
       
       //Actual code
       window.getValues = function (val1, val2, elem) {
       var BtnID = elem.getAttribute('id');
       yAxis[BtnID].setExtremes(val1, val2);     
       
    
       // If I directly use onclick ID to setExtremes instead of window.getValues, it always works. But not able to pass dialog val1 val2.Have harcoded below.
             $("#0").click(function () {
                 yAxis[0].setExtremes(4, 8);
             });

                
       }

   });
 }
Tar270
  • 57
  • 1
  • 10

1 Answers1

1

Not sure if this is causing the problem but why is window.getValues nested inside CreateChart function? Your Index.js should look like this:

function CreateChart(fileName) {  
    $.getJSON(fileName, function (data) {
       
       ...
       //Actual code
    });
}

function getValues(val1, val2, elem) {    
    var BtnID = elem.getAttribute('id');
    yAxis[BtnID].setExtremes(val1, val2);                  
}
Dimitris Maragkos
  • 8,932
  • 2
  • 8
  • 26