Angular-dc bar graph failing to display properly

I'm having some trouble creating a bar chart using crossfilter, dc.js, and angular-dc. The rowchart is working properly, but the barchart is not displaying the bars. When I inspect the element in Chrome, I can see the values, and when I force focus, the chart appears. I've tried various suggestions, but it seems like there are three main issues:

  1. All bars start at 0 on the x-axis.
  2. The width of each bar is only 1px.
  3. The bars are not rendering on the screen.

Can someone provide a solution to the above problems? I followed this link to create my barchart: https://github.com/TomNeyland/angular-dc/blob/master/example/stocks/nasdaq.html

Is there any other helpful link related to creating bar charts using angular-dc?

Here is a snippet of the code being used:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>dc.js - Pie Chart Example</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="public/lib/dcjs/web/css/dc.css"/>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
    <script type="text/javascript" src="public/lib/d3/d3.js"></script>
    <script type="text/javascript" src="public/lib/crossfilter/crossfilter.js"></script>
    <script type="text/javascript" src="public/lib/dcjs/dc.js"></script>
    <script type="text/javascript" src="public/lib/angular/angular.js"></script>
    <script type="text/javascript" src="public/lib/angular-dc/dist/angular-dc.js"></script>
</head>
<body ng-app="app">
<div ng-controller="myController">
    <div dc-chart="pieChart"
         dc-chart-group="1"
         dc-width="780"
         dc-height="480"
         dc-inner-radius="100"
         dc-dimension="fruit"
         dc-group="fruitSales"
         dc-legend="dc.legend()">
    </div>
    <div dc-chart="barChart"
         dc-width="780"
         dc-height="480"
         dc-dimension="fruit"
         dc-group="fruitSales"
         dc-x="d3.scale.ordinal().domain(['','Apple','Banana'])"
         dc-xUnits ="dc-units-ordinal"
         dc-elastic-y="true"
         dc-center-bar="true"
         dc-gap="1"
         dc-bar-padding="0.5"
         dc-xAxisPadding="50"
         dc-legend="dc.legend()">
    </div>
    </div>
</div>
<script type="text/javascript">
    angular.module("app", ["angularDc"]);
    myController = function($scope) {
        var fruitCf =  crossfilter([
            {Name: 'Apple', Sales: 40},
            {Name: 'Apple', Sales: 40},
            {Name: 'Banana', Sales: 20}]);
        $scope.fruit  = fruitCf.dimension(function(d) {return d.Name;});
        $scope.fruitSales = $scope.fruit.group().reduceSum(function(d) {return d.Sales;});
    };
</script>
</body>
</html>

Answer №1

Just recently, I attempted to solve a similar issue and explored various solutions provided in the following links:

Dealing with Angular dc.js filter problem

Resolving dc.js x axis ordinal chart problem

Unfortunately, none of those solutions worked for me. However, I made a breakthrough today by incorporating dc.js Plain Javascript directly into my controller, and it worked flawlessly. Surprisingly, you don't even need to inject the "angularDc" dependency into your application.

If you're facing a similar challenge, I recommend giving this approach a try:

<body ng-app="app">
<div id="England_batting" ng-controller="myController"></div>
<script>
    var app = angular.module("app", []);
    app.controller('myController', function($scope) {

        d3.json('New.json', function(error, data) {
            var data = data.Cricket;

            var ndx = crossfilter(data);
            dateDim = ndx.dimension(function(d) {
                return d.Date;
            });
            var a = dateDim.filter("abdul");
            var b = a.top(Infinity);
            var c = crossfilter(b);

            inningDim = c.dimension(function(d) {

                return d.Inning;

            });
            var d = inningDim.filter("Australia bowling");
            var e = d.top(Infinity);
            var f = crossfilter(e);

            nameDim = f.dimension(function(d) {

                return d.Name;

            });

            runName = nameDim.group().reduceSum(function(d) {

                return d.Runs;

            });


            var England_batting = dc.barChart("#England_batting");
            England_batting.width(700)
                .height(480)
                .gap(30)
                .yAxisLabel(".", 50)
                .xAxisLabel("U", 50)
                .dimension(nameDim)
                .group(runName)
                .x(d3.scale.ordinal().domain(nameDim))
                .xUnits(dc.units.ordinal)
                .y(d3.scale.linear().domain([0, 200]))
                .elasticY(true)
                .renderHorizontalGridLines(true)
                .renderTitle(true)
                .brushOn(true);
            dc.renderAll();

        });

    });
</script>

I hope this solution proves to be helpful for you. Best of luck! :)

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

Basic JavaScript framework centered around the Document Object Model (DOM) with a module structure similar to jQuery. Currently facing challenges with

In order to create a simple framework with jQuery style, I have written the following code: (function(window) { window.smp=function smpSelector(selector) { return new smpObj(selector); } function smpObj(selector) { this.length = 0; if (!s ...

Pausing until the user clicks the button again

I have implemented two buttons on this page - one with a class of 'arrow-up' and the other with a class of 'arrow-down'. Clicking on the 'arrow-down' button will smoothly scroll down to the next section, while clicking on the ...

Having trouble with implementing ng-hide and ng-show functionality

I have been working on creating my very first Angular website and so far, everything has been going smoothly with the first page. However, I am facing an issue with the second page not appearing as expected when it meets the condition set with ng-show in t ...

Issues with CSS causing items to not line up in a single row

I'm currently working on an html/css page and trying to align the items of the agenda class in the same row, centered on the page. https://i.sstatic.net/8TjG8.png Here's the code I've been using: <html lang="en" xmlns="ht ...

Error: The module '../lib/cli' could not be located

As someone new to the world of JavaScript development, I'm encountering an error while working through the backbone_blueprints book. Here's the specific error message I've come across: > <a href="/cdn-cgi/l/email-protection" class="__ ...

Div element remains fixed in width while zooming in

I'm encountering an issue with a centered div, where the width is set to 50% and the max-width is set to 100%. When I zoom in, the width remains constant but the height increases. Despite setting the max-width to 100%, why does this occur? And most im ...

Why does findOneandReplace continue to throw an error stating: "Error: Atomic operators are not allowed in the replacement document"?

I am currently working on a Pokemon Team Builder application with a React front end and an Express back end using MongoDB for the database. After reviewing my TeamSchema, it seems that there are no atomic operators included. Take a look at my TeamSchema b ...

What causes the generation of an outdated object when utilizing the let and new keywords to create a new object within a service function?

Hey there, looking for a basic auth authentication service in angular2? Here's the issue I'm facing: When a user logs in for the first time, everything works smoothly. However, if they try to log in with a different account for the second time, ...

The style attribute is triggering an error stating that 'Every child in a list must possess a distinct "key" property.'

Can anyone explain why I'm encountering an error when storing JSX code in a variable like this? const centerStyle = {textAlign: 'center'}; viewState.myContent = ( <Fragment> <p style={centerStyle}>Some text</p> < ...

Sometimes, JQuery struggles to set input values accurately

Exploring the single page app sample provided here, I have encountered some anomalies when attempting to manipulate input controls with JQuery under certain conditions. Below is the consistent HTML structure followed by the JavaScript snippets in question. ...

Tips for Navigating and Scrolling to an Element by its ID in a Next.js Page Enhanced with AnimatePresence

Currently, I am utilizing Framer Motion to add animations to the page transitions in a Next.js project. However, when implementing AnimatePresence, it seems to interfere with the navigation to specific elements using hash links (id). The seamless transitio ...

Error in React-Native: Unable to locate main project file during the build process

Just integrated cocoapods into a React Native project. After a successful build, RN is throwing this error... https://i.stack.imgur.com/czn2W.png No errors in Xcode during the build process, but Xcode is displaying these warnings https://i.stack.imgur.c ...

JSF CommandLink malfunctions on Firefox when reRendering an entire form

I am currently working on a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was previously designed only for IE6 browsers. However, we now need to extend our support to include Firefox as well. On one of the pages, there is a form with a button tha ...

Firefoxx effortlessly glides divs across the screen as if they were images

Below is the HTML, CSS, and JavaScript code all in one document for testing: <style type="text/css"> #slider_container { width: 200px; height: 30px; background-color: red; display:block; } #slider { width: 20px; height: 30px ...

React JS routes function properly only upon being reloaded

Encountering a problem with my reactJS routes where the URL changes in the address bar when clicking on a link, but the component does not render unless I refresh the page. Here is an excerpt from my code: index.js import React, { Component } from &apos ...

What steps can I take to persistently subscribe to SignalR from an Angular service even in the event of connection failures?

Is there a way to safely attempt to connect to SignalR with intervals between attempts until the connection is established? Also, does anyone have advice on how to handle the different stages of connectivity to the web sockets effectively? We are utilizin ...

Eliminate elements from an array using a specific key for filtering

My Array is called MainArray MainArray=[{ {First Name: "First Name"}, {Last Name: "Contact"}, {Last Name: "Contact"} ] I am trying to trim the key-value pair from this array like this: if (key == 'First Name') { del ...

Is there a way to set a default value for the map function?

Currently utilizing React.js with the following code snippet: myArray.map(variable=>({value: variable.value, label: variable.label})) It's working well for the most part, but occasionally encountering this issue: TypeError : myArray is null Any s ...

.fetchevery(...).then has no function

I recently upgraded Angular to version 1.6.4. As a result, I made changes to the code by replacing .success and .error with .then However, now I am encountering the following error: An unexpected TypeError occurred: .getAll(...).then is not a function ...

What are the recommended methods for updating data using mongoose?

There are two methods for updating data with mongoose. Using model methods, such as User.updateOne({username}, {$set: {age}}) Finding the document, making changes to its properties, and saving it. Like this: const user = await User.findById(userId) user. ...