dc.js bar graph bars blending together

This datetime barChart is causing me some trouble. Interestingly, when I try to replicate the issue in a fiddle (check here), everything functions as expected. Please note that the data takes about 30 seconds to load from github.

Below is the code for the graph :

    pnlPerDaybarChart
    .height(300)
    .width(700)
    .dimension(dims.date)
    .group(groups.date.pnlSum)
    .valueAccessor(function(d) {
        return Math.abs(d.value);
    })
    .renderTitle(false)
    .x(d3.time.scale().domain([minDate,maxDate]))
    .xUnits(d3.time.days)
    .colors(colorChoice)
    .colorAccessor(function(d) {
            if (+d.value>0) {
                return("positive");
            } else {
                return("negative");
            }
        })
    .brushOn(true)
    .elasticY(true)
    .margins({left: 70 ,top: 10, bottom: 30, right: 50})
    .centerBar(true);

Is there something obvious that I might be missing here? If not, any suggestions on where to begin debugging? I've already invested quite a bit of time into this and haven't been able to identify any issues.

UPDATE: Upon removing the .xUnits instructions, the bars become very slim but are correctly positioned along the axis. This leads me to suspect an error in the calculation of bar width. However, I'm unsure how to investigate that specific calculation. Any insight would be greatly appreciated.

UPDATE 2: The width attribute of the

<g class="chart-body"><g class="stack _0"><rect class="bar"></rect></g></g>
elements within the svg all seem to have incorrect values. If someone could direct me to where this calculation occurs in the d3 library, it may help me resolve the issue.

UPDATE 3: I've identified the root cause of my problem. It appears that the width of the bars is inaccurate because the calculateBarWidth() function only runs once during graph instantiation and doesn't execute again even when dc.redrawAll() is called. In my scenario, I continuously add data chunks to my crossfilter and redraw the graphs. My new query is - "How can I prompt calculateBarWidth() to rerun?"

Answer №1

.on("update", function (graph) {
        graph.refresh();
    });
    chart.on("beforeRender", function (graph) {
        graph.refresh();
    });

This solution is sourced from this discussion.

Answer №2

Perhaps you should check out barChart.calculateBarWidth in the src/bar-chart.js file if you're thinking of making a PR ;)

Some other issues have been reported recently regarding ordinal bar charts:

https://github.com/dc-js/dc.js/issues/533

I'm not sure if there is also a bug related to dates. It's strange that the code works in a fiddle but not on your page... that's quite unusual.

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

Tips for handling the accent mark (diacritic mark)

My primary language is Spanish, which means I use accent marks quite frequently (á, é...). When I need to type them out, I resort to using &aacute;, &eacute;, and so on. However, I'm facing an issue when trying to compare two sentences in m ...

What causes a statically generated page to appear without any style when transmitted to the client?

After setting up the Next.js official boilerplate with npx create-next-app and opening it in the browser, I observed that the static HTML document lacks styling: https://i.stack.imgur.com/mna6K.png I am concerned about potential FOUC issues. How can I en ...

Is there a way to hide the borders between cells within these divs?

I am working on an application screen using Vue.js and facing an issue with the divisions between cells. I want to hide these divisions so that the lines of the items appear continuous. I attempted to modify the classes of the columns to "col-md" and "col ...

Issue with parsing JSON data for heatmap in Mapbox

Here's the code I'm using: heat = L.heatLayer([], { maxZoom: 12 }).addTo(map); $.getJSON("js/example-single.geojson", function(data) { var geojsosn = L.geoJson(data, { onEachFeature: function (feature, layer) { console.log(f ...

Adding the Edit action in React-Redux is a crucial step towards creating a dynamic

I am looking to add an edit action to my blog page in addition to the existing ADD, DELETE and GET actions. Any suggestions on how I can implement the EDIT action to make my blog editable with just a button click? Your help would be greatly appreciated. ...

Inspect the json data to find a specific value and then determine the corresponding key associated with

I am currently working with JSON data retrieved from which I am storing in a variable. Despite my limited experience with JSON/JS, I have been unable to find a solution through online searches. Here is the code snippet: function checkMojang() { var moj ...

Any ideas on how to extract binary data from PHP passthru using a JavaScript ajax request?

I am facing an issue with retrieving and playing an audio file from a server using JavaScript. The ajax call in my code doesn't seem to callback, and I'm not certain if I'm handling the audio correctly in JavaScript. Below is the PHP file t ...

React Material-UI is notorious for its sluggish performance

I recently started using React Material-ui for the first time. Whenever I run yarn start in my react app, it takes quite a while (approximately 25 seconds) on my setup with an i5 8400 + 16 GB RAM. Initially, I suspected that the delay might be caused by e ...

Can jQuery be used to target pseudo elements such as scrollbars for selection?

Can you use jQuery to target pseudo elements like these: ::-webkit-scrollbar ::-webkit-scrollbar-track ::-webkit-scrollbar-thumb Is it possible to manipulate them through jQuery? #scroller { background: #fff; height: 300px; wid ...

Create a new tab without triggering the pop-up blocker by utilizing an iframe's JavaScript event

I currently have an iframe embedded in a webpage. Once data is successfully sent to the server within the iframe, the server responds with a new URL to be opened either in a new tab or the parent window. The main issue I am encountering is that the brows ...

Updating a deeply nested value with React's setState

Dealing with a deeply nested object in my React state has been quite the challenge. The task at hand is to modify a value within a child node. Fortunately, I have already identified the path leading to the node that needs updating and I am utilizing helper ...

Tips for implementing try-catch with multiple promises without utilizing Promise.all methodology

I am looking to implement something similar to the following: let promise1 = getPromise1(); let promise2 = getPromise2(); let promise3 = getPromise3(); // additional code ... result1 = await promise1; // handle result1 in a specific way result2 = await ...

Discover the ins and outs of utilizing the Google+ Hangout API specifically for chatting purposes

I am currently working on a webpage and I want to include a hangout button that will allow users to connect with me and start chatting automatically when clicked. Here is the code I have so far: <script src="https://apis.google.com/js/platform.js" asy ...

Analyzing the HTTP status codes of various websites

This particular element is designed to fetch and display the HTTP status code for various websites using data from a file called data.json. Currently, all sites are shown as "Live" even though the second site does not exist and should ideally display statu ...

Creating a timer implementation in Node.js using Socket.IO

In the process of developing a drawing and guessing game using node.js and socket.io, I have a structure consisting of a Room class, a Game class (which is an extension of Room), and a Round class where each game consists of 10 rounds. During each round, a ...

Looking for a drag-and-drop solution using Vanilla Javascript, no need for jQuery

Looking for assistance with creating a click-and-drag solution for a background image using Vanilla Javascript. I came across a jQuery solution on Codepen, but I need help translating it into Vanilla Javascript. Draggable.create(".box", { ...

I am experiencing issues with editing the text field in React Tab as it keeps getting out of focus

Whenever I try to type, the text box loses focus and only allows me to type one letter at a time. Below is the code snippet that I am using: <TabPanel value={value} index={0}> {[...Array(commentCount)].map((item, index) => { return ( & ...

Adding ngrx action class to reducer registration

Looking to transition my ngrx actions from createAction to a class-based approach, but encountering an error in the declaration of the action within the associated reducer: export enum ActionTypes { LOAD_PRODUCTS_FROM_API = '[Products] Load Products ...

Checking a bcrypt-encrypted password in an Express application

I am encountering an issue with my login password verification code. Even when the correct password is entered, it is not being validated properly. Can anyone provide assistance with this problem? login(req, res) { const { email, pass } = req.body; ...

Error message in Node.js with Multer: The function '.array' is not recognized

I've spent the last two days searching for a solution to this issue, but the only reference I could find was an unresolved problem reported on version 1.1.0: https://github.com/expressjs/multer/issues/338 I am using the Node.js SDK and Express framew ...