Switching Between 2 Microsoft Charts in JavaScript with Radio Buttons

Looking for a solution to switch between two MS charts based on radio button selection using JavaScript, ASP.NET, and VB.

1) Problem solved: The radio buttons now alternate between the charts, but both are visible when the page loads. I want only one chart to be displayed initially.

2) The charts should replace each other in the same position. Currently, they are stacked vertically and leave white space when made invisible.

Check out the code below:

Chart Component

<table>
<tr>
    <td>
        <div id="HomeAutoContainer" runat="server">
            <div id="BindsAuto" runat="server">
                <asp:Chart ID="chTotalBindsAuto" runat="server" Height="230px" Width="280px">
                    <Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </div>
            <div id="BindsHome" runat="server">
                <asp:Chart ID="chTotalBindsHome" runat="server" Height="230px" Width="280px">
                    <Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </div>
        </div>
    </td>
</tr>
<tr>
    <td style="vertical-align: top" align="center">
        <asp:RadioButtonList ID="rdoBindsList" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="Auto" Text="Auto" Selected="True">Auto</asp:ListItem>
            <asp:ListItem Value="Home" Text="Home">Home</asp:ListItem>
        </asp:RadioButtonList>
    </td>
</tr>

Page Load of the component

rdoBindsList.Attributes.Add("OnClick", "BindsAutoHomeSwitch('" + rdoBindsList.Items(0).ToString + "','" + BindsAuto.ClientID + "','" + BindsHome.ClientID + "' );")

JavaScript function

function BindsAutoHomeSwitch(rdoAutoHomeID, chTotalBindsAuto1, chTotalBindsHome1) {
        var rdoAutoHome = document.getElementById("ctl00_ContentArea_AutoTotalBinds1_rdoBindsList_0");
        var chTotalBindsHomeGraph = document.getElementById(chTotalBindsHome1);
        var chTotalBindsAutoGraph = document.getElementById(chTotalBindsAuto1);
        var selectedGraphValue
        if (rdoAutoHome.checked) {
            selectedGraphValue = "Auto"
        }
        else {
            selectedGraphValue = "Home"
        }


        if (selectedGraphValue == "Home") {
           chTotalBindsAutoGraph.style.visibility = "hidden";
           chTotalBindsHomeGraph.style.visibility = "visible";

        }
        if (selectedGraphValue == "Auto") {
            chTotalBindsAutoGraph.style.visibility = "visible";
            chTotalBindsHomeGraph.style.visibility = "hidden";
        }
    }

Answer №1

RESOLVING LOADING ISSUE: The solution involved incorporating a JavaScript function and triggering it during page load to handle the visibility.

Page Load

rdoBindsList.Attributes.Add("OnClick", "BindsAutoHomeSwitch('" + rdoBindsList.Items(0).ToString + "','" + BindsAuto.ClientID + "','" + BindsHome.ClientID + "' );")
        Page.ClientScript.RegisterStartupScript(Me.GetType, "HideHome", "HideHomeGraphOnLoad('" + BindsHome.ClientID + "' );", True)

JavaScript Function

function HideHomeGraphOnLoad(chTotalBindsHome1) {
        var chTotalBindsHomeGraph = document.getElementById(chTotalBindsHome1);
        chTotalBindsHomeGraph.style.visibility = "hidden";
    }

RESOLVING CHART STACKING : Positioning adjustments were required on specific DIV elements to achieve the desired outcome.

<table>
<tr>
    <td>
        <div id="HomeAutoContainer" runat="server" style="position:relative; width:280px; height:230px">
            <div id="BindsAuto" runat="server" style="position: absolute; top: 0; left: 0;">
                <asp:Chart ID="chTotalBindsAuto" runat="server" Height="230px" Width="280px">
                    <Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </div>
            <div id="BindsHome" runat="server" style="position: absolute; top: 0; left: 0;">
                <asp:Chart ID="chTotalBindsHome" runat="server" Height="230px" Width="280px">
                    <Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </div>
        </div>
    </td>
</tr>
<tr>
    <td style="vertical-align: top;" align="center">
        <asp:RadioButtonList ID="rdoBindsList" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="Auto" Text="Auto" Selected="True">Auto</asp:ListItem>
            <asp:ListItem Value="Home" Text="Home">Home</asp:ListItem>
        </asp:RadioButtonList>
    </td>
</tr>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The welcome message in Discord.js is displaying the user as a string of numbers instead of their real username

bot.on('guildMemberAdd', user =>{ const greetingMessage = new Discord.MessageEmbed() .setTitle(`Welcome to the server, ${user.user}! We're glad you've joined.`) const channel = user.guild.channels.cache.find(channel =&g ...

Is there a way to activate a click event on a particular child element within a parent element?

When attempting to click on a specific descendant of an element, I located the ancestor using ng-class since it lacked an id. yes = document.querySelectorAll('[ng-controller = "inventoryController"]') Having found the desired ancestor, ...

When implementing fancybox within bxslider, numerous thumbnails are shown simultaneously

My issue arises when using fancybox within bxslider. Once I open an image, multiple thumbnails start repeating themselves endlessly. This problem only started occurring after adding bxslider. Any thoughts on why this might be happening? ...

Implementing ngClass on a paragraph with Radio Buttons for dynamic styling

In my home.css file, I created two classes named 'male' and 'female'. I also added two radio buttons with values 'male' and 'female'. My goal is to change the background color of a paragraph when I select one of thes ...

Error: Undefined variable in JavaScript obfuscation

My website has several small JavaScript files that I currently merge into one file and then minimize using terser. The website functions perfectly with the minimized version. Now, I want to take it a step further and obfuscate the code using JavaScript-Ob ...

The removal of the Lodash library from node modules is not occurring

In an effort to reduce bundle size, I made the decision to replace all lodash methods with core js methods in my Vuejs project. Despite attempting various npm uninstall commands such as: npm uninstall lodash npm uninstall lodash --save npm uninstall lodas ...

Loading screen in Next.js

Is there a way to implement a loader page during transitions within the same web application using Next JS? During development, the pages transition smoothly with the CSS applied correctly. However, when moving the application to production environment, t ...

Tips for ensuring proper function of bullets in glidejs

I am currently working on implementing glidejs as a slider for a website, but I am facing issues with the bullet navigation. The example on glidejs' website shows the bullets at the bottom of the slider (you can view it here: ). On my site, the bullet ...

The Mongoose .lt method is unable to process the post value

I came across this interesting Mongoose function snippet: exports.readSign = function(req, res) { if (req.user.roles.indexOf('admin') === 1) { Timesheet.find() .where('projectId').equals(req.params.projectId) ...

I don't understand why my page loses all its design when I refresh it and it has a URL with an ID in vue-router

Whenever I try to redirect from the target component to the target-details component using a specific ID, I encounter an error when refreshing the page: javascript Uncaught SyntaxError: Unexpected token '<' app.js:1. Additionally, after cl ...

Differences between Absolute URLs in HTML files on Servers and in Local Environments

I have configured absolute paths for images on my website. The directory structure is as follows: Root Client -- Images ---a.png -- Index.html When using a.png in Index.html, I set the src as "/client/Images/a.png". This works fine on the serv ...

Returning false will not terminate the each loop in cypress testing

Here is the code snippet I am working with: cy.get('[data-testid="userRecords"]') .each((record) => { if (record.find('[data-testid="delete"]').is(":enabled")) { cy.wrap(record).find(& ...

Exploring the depths of ES6 with cascading promises

Currently grappling with a dilemma while working with promises - it's more of a Best Practice question. I have a function that returns a promise resolving into a validated object: validate(req.body, bodyValidationSchema) Another function creates an ...

A dynamic jQuery plugin for creating captivating image slideshows

I am in need of a recommendation for a jQuery carousel plugin that has the capability to create a carousel similar to the one shown in the image. Specifically, I am looking for a carousel where the active image item moves to the center and becomes larger. ...

Step-by-step guide on adding a div inside another div:1. Start

Hey there! I'm currently in the process of building a website using PHP. One of the features on the site is a form for adding appointments. Users can input the date, start time, and end time of their appointment. Additionally, users have the ability t ...

Obtain the source of the request when it is generated internally rather than by the

I need to ensure that only one specific web API can make requests to another API, with all other APIs being restricted. I have implemented CORS, but since the request is coming from an API, there is no origin information present in the request. Is there a ...

An error occurred stating 'TypeError: jsdom.jsdom is not a function' while using the paper-node.js in the npm paper module

Recently, I added the webppl-agents library to my project, including webppl and webppl-dp. However, when attempting to execute the command line test, I encountered some difficulties. It seems that there is a dependency problem with jsdom from the npm paper ...

What methods can a Java application use to distinguish one browser from another?

Is there a way to determine if the browser being used is Firefox or Chrome? I am looking to create an application that will only run on a specific browser registered by a user. To achieve this, my application needs to be able to identify which browser the ...

Mastering the art of jQuery UI development, similar to the techniques

I'm currently working on creating an abstraction layer for jQuery UI that enables the definition of Widgets as Objects, similar to ExtJS. Here's how it works: var mydialog = new $.ui.dialog({ modal:true, renderTo:'body', title:'T ...

Using Javascript to Populate HTML Text Fields

Is it possible to store the contents of an HTML element in a Javascript variable? I have a form that is populated with data from a database. I want users to be able to update the form values, click a button, and have those changes reflected back in the da ...