Axis properties not updating properly

I have a previous post in this thread that describes my use of charts. Now, I am having an issue where the axes I have defined won't change properties.


I have an event handler on legend click like this:

protected void OnLegendClick(LegendClickEventArgs args)

        {

            var name = args.Series.Name;

            bool needsUpdate = false;

            switch (name)

            {

                case "Demand":

                    if ((GraphAverageDemandVisible || GraphAverageBookingsVisible) != (!GraphAverageDemandVisible || GraphAverageBidsVisible))

                        needsUpdate = true;

                    GraphAverageDemandVisible = !GraphAverageDemandVisible;

                    break;

                case "Bids":

                    if ((GraphAverageDemandVisible || GraphAverageBookingsVisible) != (GraphAverageDemandVisible || !GraphAverageBidsVisible))

                        needsUpdate = true;

                    GraphAverageBidsVisible = !GraphAverageBidsVisible;

                    break;

                case "Bookings":

                    needsUpdate = true;

                    GraphAverageBookingsVisible = !GraphAverageBookingsVisible;

                    break;

                case "Bid Rate":

                    if ((GraphBidRateVisible || GraphBookRateVisible) != (!GraphBidRateVisible || GraphBookRateVisible))

                        needsUpdate = true;

                    GraphBidRateVisible = !GraphBidRateVisible;

                    break;

                case "Book Rate":

                    if ((GraphBidRateVisible || GraphBookRateVisible) != (GraphBidRateVisible || !GraphBookRateVisible))

                        needsUpdate = true;

                    GraphBookRateVisible = !GraphBookRateVisible;

                    break;

                case "Revenue":

                    if ((GraphAverageRevenueVisible || GraphRPDVisible) != (!GraphAverageRevenueVisible || GraphRPDVisible))

                        needsUpdate = true;

                    GraphAverageRevenueVisible = !GraphAverageRevenueVisible;

                    break;

                case "RPD":

                    if ((GraphAverageRevenueVisible || GraphRPDVisible) != (GraphAverageRevenueVisible || !GraphRPDVisible))

                        needsUpdate = true;

                    GraphRPDVisible = !GraphRPDVisible;

                    break;

                case "Scheduled":

                    GraphScheduledVisible = !GraphScheduledVisible;

                    break;

                case "Ad Hoc":

                    GraphAdHocVisible = !GraphAdHocVisible;

                    break;

                default:

                    break;

            }

            var demandBidsMax = ConditionalMax(performanceGraphData, demand: GraphAverageDemandVisible, bids: GraphAverageBidsVisible);

            var ratesMax = ConditionalMax(performanceGraphData, bidRate: GraphBidRateVisible, bookRate: GraphBookRateVisible);

            var bookingsMax = ConditionalMax(performanceGraphData, bookings: GraphAverageBookingsVisible);

            var revenueMax = ConditionalMax(performanceGraphData, revenue: GraphAverageRevenueVisible, rpd: GraphRPDVisible);

            if (demandBidsMax != null)

            {

                GraphIntervalDemandBids = Nearest5Multiple((decimal)demandBidsMax / 10);

                var maxRound = Nearest5Multiple((decimal)demandBidsMax);

                if(GraphMaxDemandBids != maxRound)

                {

                    GraphMaxDemandBids = maxRound;

                    needsUpdate = true;

                }

            }

            if (ratesMax != null)

            {

                GraphIntervalRates = Nearest5Multiple((decimal)ratesMax / 10);

                var maxRound = Nearest5Multiple((decimal)ratesMax);

                if(GraphMaxRates != maxRound)

                {

                    GraphMaxRates = maxRound;

                    needsUpdate = true;

                }

            }

            if (bookingsMax != null)

            {

                GraphIntervalBookings = Nearest5Multiple((decimal)bookingsMax / 10);

                var maxRound = Nearest5Multiple((decimal)bookingsMax);

                if(GraphMaxBookings != maxRound)

                {

                    GraphMaxBookings = maxRound;

p>                    needsUpdate = true;

                }

            }

            if (revenueMax != null)

            {

                GraphIntervalRevenue = Nearest5Multiple((decimal)revenueMax / 10);

                var maxRound = Nearest5Multiple((decimal)revenueMax);

                if(GraphMaxRevenue != maxRound)

                {

                    GraphMaxRevenue = maxRound;

                    needsUpdate = true;

                }

            }

            if (needsUpdate)

                args.Chart.RefreshAsync();

        }

And I have the chart defined thusly:

<TabItem>

                                            <ChildContent>

                                                <TabHeader Text="Performance Grid"></TabHeader>

                                            </ChildContent>

                                            <ContentTemplate>

                                                <div class="mt-lg-4">

                                                    <SfChart Width="100%" Height="100%">

                                                        <ChartEvents SharedTooltipRender="OnTooltipRender" OnLegendClick="OnLegendClick"></ChartEvents>

                                                        <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Double" Minimum="0" Maximum="23" Interval="1">

                                                            <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                            <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                        </ChartPrimaryXAxis>

                                                        <ChartAxes>

                                                            <ChartAxis Name="YAxis2" ValueType="Syncfusion.Blazor.Charts.ValueType.Double"

                                                                       Visible="@GraphAverageBookingsVisible" Interval="@GraphIntervalBookings"

                                                                       Minimum="0" Maximum="@GraphMaxBookings">

                                                                <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                                <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                            </ChartAxis>

                                                            <ChartAxis Name="YAxis1" ValueType="Syncfusion.Blazor.Charts.ValueType.Double"

                                                                       Visible=@(GraphAverageDemandVisible || GraphAverageBidsVisible) Interval="@GraphIntervalDemandBids"

                                                                       Minimum="0" Maximum="@GraphMaxDemandBids">

                                                                <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                                <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                            </ChartAxis>

                                                            <ChartAxis Name="YAxis3" ValueType="Syncfusion.Blazor.Charts.ValueType.Double" OpposedPosition="true"

                                                                       Visible=@(GraphBidRateVisible || GraphBookRateVisible) Interval="@GraphIntervalRates"

                                                                       Minimum="0" Maximum="@GraphMaxRates">

                                                                <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                                <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                            </ChartAxis>

                                                            <ChartAxis Name="YAxis4" ValueType="Syncfusion.Blazor.Charts.ValueType.Double" OpposedPosition="true"

                                                                       Visible=@(GraphAverageRevenueVisible || GraphRPDVisible) Interval="@GraphIntervalRevenue"

                                                                       Minimum="0" Maximum="@GraphMaxRevenue">

                                                                <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                                <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                            </ChartAxis>

                                                            <ChartAxis Name="YAxis5" ValueType="Syncfusion.Blazor.Charts.ValueType.Double" Visible="false">

                                                                <ChartAxisMinorGridLines Width="0"></ChartAxisMinorGridLines>

                                                                <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>

                                                            </ChartAxis>

                                                        </ChartAxes>

                                                        <ChartCrosshairSettings Enable="true" LineType="LineType.Vertical"></ChartCrosshairSettings>

                                                        <ChartTooltipSettings Enable="true" Shared="true"></ChartTooltipSettings>

                                                        <ChartArea>

                                                            <ChartAreaBorder Width="0"></ChartAreaBorder>

                                                        </ChartArea>

                                                        <ChartSeriesCollection>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphAverageDemandVisible"

                                                                         YName="AverageDemand" Type="ChartSeriesType.Line" Name="Demand" Width="3" YAxisName="YAxis1">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphAverageBidsVisible"

                                                                         YName="AverageBids" Type="ChartSeriesType.Line" Name="Bids" Width="3" YAxisName="YAxis1">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphAverageBookingsVisible"

                                                                         YName="AverageBookings" Type="ChartSeriesType.Line" Name="Bookings" Width="3" YAxisName="YAxis2">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphBidRateVisible"

                                                                         YName="BidRate" Type="ChartSeriesType.Line" Name="Bid Rate" Width="3" YAxisName="YAxis3">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphBookRateVisible"

                                                                         YName="BookRate" Type="ChartSeriesType.Line" Name="Book Rate" Width="3" YAxisName="YAxis3">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphAverageRevenueVisible"

                                                                         YName="AverageRevenue" Type="ChartSeriesType.Line" Name="Revenue" Width="3" YAxisName="YAxis4">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@performanceGraphData" Visible="@GraphRPDVisible"

                                                                         YName="RPD" Type="ChartSeriesType.Line" Name="RPD" Width="3" YAxisName="YAxis4">

                                                                <ChartMarker Visible="true"></ChartMarker>

                                                                <ChartSeriesAnimation Enable="true" Delay="0" Duration="125"></ChartSeriesAnimation>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@scheduleStartTimes" Visible="@GraphScheduledVisible"

                                                                         YName="Height" Type="ChartSeriesType.Scatter" Name="Scheduled" YAxisName="YAxis5">

                                                                <ChartMarker Visible="true" Shape="ChartShape.Circle"

                                                                             Height="15" Width="15"></ChartMarker>

                                                            </ChartSeries>

                                                            <ChartSeries XName="Hour" DataSource="@adHocStartTimes" Visible="@GraphAdHocVisible"

                                                                         YName="Height" Type="ChartSeriesType.Scatter" Name="Ad Hoc" YAxisName="YAxis5">

                                                                <ChartMarker Visible="true" Shape="ChartShape.Diamond"

                                                                             Height="15" Width="15"></ChartMarker>

                                                            </ChartSeries>

                                                        </ChartSeriesCollection>

                                                        <ChartLegendSettings Visible="true" Width="500"></ChartLegendSettings>

                                                    </SfChart>

                                                </div>

                                            </ContentTemplate>

                                        </TabItem>

I have also attached relevant files, in order to help show what's happening.

I am expecting the axes to be no longer visible when the property that is set to their Visible property is set to false.

Additionally, the interval and max properties don't seem to be updating at that time, either.


Attachment: AxisPropertiesNotUpdating_31f380b0.zip

5 Replies

AS Adam Schubach October 19, 2021 01:14 PM UTC

To clarify, since my problem may not be that clear: I have certain series set to certain Y axes. When none of the associated series are visible, I want the Y axis to become invisible.

In this example, I have disabled the Demand and Bids series.

However, the near left axis (YAxis1) doesn't update its maximum, nor does it lose visibility:


As written above, the visibility of that series is set thus: Visible=@(GraphAverageDemandVisible || GraphAverageBidsVisible)

  As you can see here, when RefreshAsync() is called on the Chart via the OnLegendClick args, both of those properties are set to false:


I have tried making my event handler an async Task, and await both the event handler and the RefreshAsync method, but that doesn't change the behavior.

I have attempted to use the Blazor @bind-<propertyName> syntax, but Syncfusion.Blazor isn't set up to use that convention.

The behavior was partially correct when I was using UpdateChart(), using a previous version of Syncfusion.Blazor.



AS Adam Schubach October 19, 2021 02:39 PM UTC

I ended up being able to affect the visibility of the axes with this event handler:


However, I get a warning stating "Component parameter 'Visible' should not be set outside of its component."

I want to achieve this effect without using unintended methodology; however, this seems to be my best option as of right now. If I could get an opinion on either

  1. Is this a supported method of updating the visibility of the chart axes, and
  2. What is a different, supported way of achieving this while still being updated to 19.3.*?
Thanks in advance


DG Durga Gopalakrishnan Syncfusion Team October 19, 2021 04:30 PM UTC

Hi Adam, 

We are validating your reported scenarios. We will update the status within one business day(20th October, 2021). We appreciate your patience until then. 

Regards, 
Durga G


DG Durga Gopalakrishnan Syncfusion Team October 21, 2021 04:31 PM UTC

Hi Adam, 

Thanks for being patience. 

We have validated your reported scenario with attached snippet. We request you to use property binding to hide axis based on clicked legend item. We have prepared sample based on your requirement. Please check with below snippet and screenshot. 

<SfChart> 
    <ChartPrimaryYAxis Visible="@yVisibility" Maximum="@maximum" Interval="@interval"> 
    </ChartPrimaryYAxis> 
    <ChartAxes> 
        <ChartAxis Visible="@y1Visibility" Name="YAxis1"> 
        </ChartAxis>                     
    </ChartAxes> 
</SfChart> 
@code {    
    public bool yVisibility = true; 
    public bool y1Visibility = true; 
 
    public double interval = 50; 
    public double maximum = 350; 
    protected void LegendClickEvent(LegendClickEventArgs args) 
    { 
        var name = args.Series.Name; 
        bool needsUpdate = false; 
        switch (name) 
        { 
            case "Demand": 
                if (args.Series.Visible) 
                { 
                    yVisibility = false; 
                } 
                else 
                { 
                    yVisibility = true; 
                } 
                needsUpdate = true; 
                break; 
        interval = 100; 
        maximum = 500; 
 
        if (needsUpdate){ 
            this.StateHasChanged(); 
        } 
 
    } 
} 

Initial rendering 
 

After legend click 
 


We have also logged a feature request on “Support to hide axis with series when clicking the legend”. Based on other logged tasks priority, this feature will be included in any of our upcoming release. You can keep track of the feature from the feedback portal below.  
  
  
If you have any more specification/precise replication procedure or a scenario to be tested, you can add it as a comment in the portal. 

Please let us know if you have any concerns. 

Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team December 28, 2022 08:45 AM UTC

Hi Adam,


We are glad to announce that our Essential Studio 2022 Volume 4 release v20.4.0.38 is rolled out; we have included the reported requirement and is available for download under the following link.


https://www.syncfusion.com/forums/179561/essential-studio-2022-volume-4-main-release-v20-4-0-38-is-available-for-download


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/HideAxis-321001423.zip


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.


Regards,          

Durga Gopalakrishnan.


Loader.
Up arrow icon