Bar graph with a right/left bar split exactly in half using Plotly.js

Issue 1:
The image of the bar graph displays that the left and right bars are cut in half. Here is a link to the image.

const drawDayGraph = (div_id) => {
    var trace1 = {
        x: [1614882600000, 1614886200000, 1614889800000, 1614893400000, 1614897000000, 1614900600000, 1614904200000, 1614907800000, 1614911400000, 1614915000000, 1614918600000, 1614922200000, 1614925800000, 1614929400000, 1614933000000, 1614936600000, 1614940200000, 1614943800000, 1614947400000, 1614951000000, 1614954600000, 1614958200000, 1614961800000, 1614965400000],
        y: [0, 0, 0, 0, 0, 0, 0.7600000000093132, 32.389999999897555, 132.72999999998137, 224.9000000001397, 310.5200000000186, 331.14999999990687, 425.2100000001956, 423.80999999982305, 391.8100000000559, 298.2399999999907, 184.95999999996275, 53.25, 2.550000000046566, 0, 0, 0, 0, 0],
        type: 'bar',
        marker: {
            color: '#FEDB41',
        },
    };
    var data = [trace1];

    var start_time = new Date(1614882600000);
    var end_time = new Date(1614882600000);
    start_time.setHours(7,0,0);
    end_time.setHours(19,0,0);
    var layout = {
        xaxis: {
            fixedrange: true,
            offset: true,
            tickformat: '%I',
            zeroline: true,
            showline: false,
            tickfont : {
                size : 10,
                color : 'white'
            },
            type: 'date',
            automargin: true,
            range:[
                start_time.getTime(),
                end_time.getTime()
            ]
        },
        "yaxis": {
            "visible": false,
            "showgrid": false,
            "zeroline": false
            },
        margin: {
            l: 2,
            r: 2,
            b: 20,
            t: 2,
        },

        paper_bgcolor: 'rgba(0,0,0,0)',
        plot_bgcolor: 'rgba(0,0,0,0)',
    };

    Plotly.newPlot(div_id , data, layout, {displayModeBar: false});
  }

The issue arises with the bar chart where the first and last bars are cut in half. The goal is to display full bars instead.

Problem 2:

I aim to indicate hours beneath each bar on the x-axis from 7 AM to 7 PM. Refer to this sample for representation - image. Currently struggling to find solutions for both issues. Any assistance would be appreciated. Thank you.

Answer №1

Please check out this updated code snippet: see the modified version here

Here are the recent modifications: The arrow function has been eliminated, and the graph plot is now assigned to a variable in the following manner:

var drawDayGraph = Plotly.newPlot('myDiv', data, layout, { displayModeBar: false });

Answer №2

To solve the initial issue, simply implement autorange: true; the range parameter will be disregarded.

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

Issue with Angular's ng-show failing to display an image post-processing

$scope.showProcessedGraph = function(hash) { if ($scope.selectedFile.hash == hash) return; $scope.graph = ""; $scope.isImageLoaded = false; $scope.isLoading = true; if (hash) { $http({ m ...

What is the best way to utilize eslint in Vue components?

I'm facing an issue with my .vue file that defines a component. Other .vue files are unable to see it properly due to linter errors. I keep getting ES Lint errors like: Cannot find module '../components/LinkButton'. I have tried several st ...

Learn the best way to populate Google Map popup windows with multiple values and include a button to pass unique ID values

I'm facing an issue with my code. When I click on a marker, it should display "Madivala, 12.914494, 77.560381,car,as12" along with a button to pass ID values. Can someone help me figure out how to move forward? http://jsfiddle.net/cLADs/123/ <ht ...

Showing JSON data stored in Local Storage

My goal is to retrieve a JSON object from local storage in the web browser and then display the values. While I am able to save the JSON object and add new data to it, I am struggling with the logic required to fetch and show it. For context, the variable ...

The Twilio JWT authentication token has expired

I'm currently utilizing Twilio voice call functionality and everything is working smoothly. However, the Twilio JWT token expires every hour, forcing users to refresh the page periodically. I'm seeking advice on how to extend the token validity p ...

Having issues with jQuery's .fadeIn function not functioning properly

Currently, I'm developing a website and I am aiming to achieve a specific effect where a text fades in every time the webpage is opened. To achieve this, I have implemented the following code snippet: $(document).ready(function() { $('#title ...

Is it possible to eradicate arrow functions in Angular CLI?

I am facing a challenge in running my code on IE11 due to issues with arrow functions. I need to find a way to eliminate them from the build and replace them with function() {}. Even though I have removed them from main.js, they are still present in the v ...

"Troubleshooting: Issues with jQuery Counter Functionality

Hey there, I'm new to JavaScript and jQuery! I've got this form set up with Bootstrap's disabled class: Note: the 'disabled' class in bootstrap properly disables and enables the button based on conditions. <form action="" met ...

Organizing outcome searches through ajax

I have a result table displayed on the left side https://i.stack.imgur.com/otaV4.png https://i.stack.imgur.com/pp9m0.png My goal is to transform it into the format shown on the right side of the table In a previous inquiry found here, @Clayton provided ...

What is the best way to display a list of search outcomes?

I've hit a roadblock trying to figure out what's happening. Despite watching videos on maps, arrow functions, and implicit returns, my code still doesn't seem to make sense. Everything checks out when I console log it, all the data is there. ...

What is the best method to ensure that a word will wrap to the next line if it exceeds the container’s size?

Hello everyone:) I am using a <div> to contain words, with a maximum length of 6 characters. My goal is to move to the next line if the word length exceeds 6 characters, but drop down to a new line if the word length is exactly 6 characters. For exam ...

Obtain the server-side cookie within the getServerSideProps function in Next.js

Attempting to implement authentication on my Next.js website. I've set up a signin endpoint at /api/users/signin where, upon verifying the user, a JWT token is generated and saved as follows: res.setHeader("Set-Cookie", `token=${token}; Htt ...

Tips for automatically refreshing the Parent page once the modal form is closed in ASP.NET Core

I am currently using asp.net core mvc 5 along with EF Core 5. On a specific page, there is a button that triggers a modal form to appear when clicked. This allows the user to create a new person. Upon submitting the modal form, a person is created and ass ...

The Ejs page is failing to render on the simplified code version

Here is the code that displays the 'post' page: app.get("/posts/:postName", function(req, res) { const requestedTitle = _.lowerCase(req.params.postName); posts.forEach(function(post) { const storedTitle = _.lowerCase(post.title ...

Creating tables using ng-repeat in AngularJS and Bootstrap

Although I am new to Angular, I have been struggling with a problem for the past few days and can't seem to find a solution. I want to create a matrix of images (charts generated by angular-chart module) with 2 columns that will dynamically load a va ...

What is the best method for comparing the JSP page response with the AJAX page response?

I am experiencing issues when trying to compare the response received from a JSP page with Ajax. I am looking to execute an action in the success Ajax function if the out.print() method prints a success message. Despite comparing the data, it seems like it ...

Form validation has not passed the necessary checks

Struggling to create a new user POST form with Bootstrap form validation but encountering an issue. The button code is as follows: <button class="btn btn-primary btn-addUser" type="submit">Add User</button> This button trig ...

Having trouble with the numbering system - any suggestions on how to resolve this issue?

I am experiencing an issue with numbering a list .content ol { padding-left: 0px; counter-reset: item; } .content ol > li { display: block; } .content ol > li::before { content: counters(item, ". ") " " ; counter-increment: ...

Sharing data between parent and child components in React

I am facing an issue with passing a dynamically generated value from child components to my parent/web component. The buttons in the child component are assigned a `value="URL"` based on MongoDB data, and I want to pass that value to my parent component us ...