Graph is not showing up when navigating through page

On my List page (List.Html), users can select multiple rows to display the data in a chart using C3. However, when clicking on the compareList() button to navigate to the Chart page (Chart.Html), the chart does not display properly. It seems that the chart data is being loaded before the page itself, causing issues with finding the HTML element to insert the chart into.

If the Chart Page loads before the list page, the chart is generated but disappears after one click.

In the Controller.js:

$scope.compareList = function(){
    var total = $scope.array.length;
    var tempArray= [];
    for(var i=0; i<total; i++){
      if($scope.array[i].selected){
        tempArray[i] = $scope.array[i];
      }
    }
    if(comparr.length>0){
      $scope.compGraph(tempArray);
    }
}

$scope.compGraph = function(array){
var tempData = [];
for(var i=0; i<array.length;i++){
  tempData.push([array[i].name,array[i].evi]);
}

var chart = c3.generate({
    bindto: '#chart',
    data: {
      columns: tempData,
      type:'bar'
    }
});

$state.go('eventmenu.compare');

}

List.Html:

<ion-view view-title="List">
        <ion-nav-buttons side="right">
            <button class="button button-icon icon ion-stats-bars" ng-click="compareList()"></button>
        </ion-nav-buttons>
        <ion-content>
            <ion-item ng-repeat="item in items" class="item-remove-animate">
                <div class="row" >
                    <div class="col col-40"{{ item.name }}</div>
                    <div class="col col-30" style=";">{{ item.area}}m<sup>2</sup></div> 
                    <div class="col col-20" style=";">{{ item.value}}</div>
                    <div class="col col-10  col-top" ><ion-checkbox style="border:none;margin-top: -20px;" ng-model="item.selected"></ion-checkbox></div>
                </div>
            </ion-item>
        </ion-list>   
    </ion-content>
    </ion-view>

Chart.Html:

<ion-view view-title="Land Comparison">
  <ion-content ng-controller="Controller">
        <div class="padding">
                <div id="chart" ></div>
        </div>
  </ion-content>
</ion-view>

Answer №1

My code includes the use of ng-if to handle charts. I set a value to monitor the loading status and utilize it accordingly.

Here is the HTML snippet:

<div class="padding">
    <div ng-if="isDataLoaded" id="chart"></div>
</div>

And in the controller:

$scope.isDataLoaded = false;

function loadData(){
    $scope.myData = [1,2,3];
    $scope.isDataLoaded = true;
}

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

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

Troubleshooting Problem: Difficulty accessing Controller in AngularJS Module

I am facing difficulties with communication between my application and a module that I have developed. Below is the AngularJS module that I created. (function (document, window) { 'use strict'; var piCart = angular.module('piCart& ...

What are some alternative methods for organizing folder structure in Express Handlebars when managing views?

Is there a more efficient way to render HTML files without constantly needing them to have different names? I'm looking for a method where handlebars can identify which file in which folder to render, without encountering conflicts with files of the s ...

AngularJS xeditable typeahead - dynamically modify input field based on the value of another input field

Struggling with the angularjs xeditable typeahead feature. I attempted to update one input field using the value of another input field, but encountered an issue. Even after updating the $scope variable, xeditable failed to bind the new value to the HTML ...

Looking for assistance with PHP if statement and troubleshooting iFrame issues

Using the PHP if statement below on my website: <?php if(empty($_GET['tid'])) echo '<iframe src="http://tracking.mydomain.com/aff_goal?a=33&goal_id=47" scrolling="no" frameborder="0" width="1" height="1"></iframe>'; ...

Updating the jQuery mobile webpage

I have set up a small demo with two pages - the Home page and the Team 1 page. By clicking on the navigation menu, you can navigate to the Team 1 page from the Home page. However, if you are already on the Team 1 page and click on the Team 1 button again ...

The HiddenField is returning empty when accessed in the code behind section

In my gridview, the information is entered through textboxes and saved to the grid upon clicking a save button. One of these textboxes triggers a menu, from which the user selects a creditor whose ID is then saved in a HiddenField. <td class="tblAddDet ...

Unlocking Extended Functionality in JQuery Plugins

At the moment, I am utilizing a JQuery Plugin known as Raty, among others. This particular plugin typically operates as follows: (function($){ $.fn.raty = function(settings, url){ // Default operations // Functions ...

The Add/Remove button functionality is not functioning as expected for duplicated form fields when using jQuery

I am experiencing an issue with the functionality of the "Add another" and "Remove row" buttons in my form. I implemented code from a specific Stack Overflow answer (jquery clone form fields and increment id) to create a cloneable section, but only the ori ...

Adjust the text color based on the background image or color

Here on this site, I have designed the first div to display a dark image, while the second one shows a light background. I am aiming to adjust the sidebar text color based on whether it is displayed against the dark or light background. How can I achieve ...

What is the method to restrict the selection of only one option for specific values in a multiple-selection dropdown menu?

Is there a way to create a dropdown menu with the following functionalities: I want to allow multiple selections for options A, B, and C, but disable multiple selection if option D is selected. Any tips on how to achieve this? Thank you. <label>Ch ...

Retrieve all documents with a matching objectId field in MongoDB

I built an API that can fetch all data from a table, but within this table there is an object ID reference to a user. Table 1 - Story | Table 2 - User api.get('/all_stories', function(req, res) { Story.find({}, function(err, stories) { ...

Developing a trivia game using HTML and JavaScript

I'm in need of some serious assistance with creating a quiz using HTML. My goal is to have a web page where users can visit, take a quiz, and have their responses stored. Unfortunately, I don't have the knowledge or skills required to do this on ...

The UI-SELECT feature in angular-js does not seem to be displaying

I've added the necessary ui-select js and css files to my page : <link href="assets/plugins/ui-select/select.min.css" rel="stylesheet" type="text/css" <script src="assets/plugins/ui-select/select.min.js" tyle="text/javascript" </script> ...

Is there a way to create an interpolated string using a negative lookahead condition?

When analyzing my code for imports, I will specifically be searching for imports that do not end with -v3. Here are some examples: @ui/components <- this will match @ui/components/forms/field <- this will match @ui/components-v3 ...

"Revamping the text style of input materials in React JS: A step-by

How can I modify the style of the text field component in Material UI? Specifically, I would like to change the appearance of the text that the user enters. I have attempted to use the Material API, but it has not provided the desired results. Here is an ...

Tips on showcasing variable values in a row using a comma separator in AngularJS

I need to showcase the values of my four variables in a single row with commas separating them. Currently, I have implemented the following code: {{first}}<span ng-show="first != '' && (second != '' || third != '' ...

Activate a function when the VueJS countdown timer hits zero

I've successfully created a countdown timer in the template that decrements a number perfectly. Now, I'm facing the challenge of triggering a function declared within the methods section once the countdown reaches 0. Despite attempting to check i ...

Executing a jQuery function only once per click on a select element - how can it be done?

I have a form with a select element, and I want some code to run when I click on it, but not when I choose an option. The issue is that the code is running twice, preventing me from selecting an option as it resets itself each time. Here is the HTML: &l ...

Removing functionality within an AngularJS application connected to a Ruby on Rails backend

I'm currently developing a task management application called "To-Do List", which is being constructed using AngularJS within the framework of Ruby on Rails. My current endeavor involves setting up a delete button, represented by an "X", to enable th ...