简体   繁体   English

条形图右/左条切成两半( Plotly.js )

[英]BarChart right/left bar cut in half ( Plotly.js )

First problem 1.第一个问题1。
Image of bargraph left and right bars are cut to half条形图左右条形的图像被切成一半

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});
  }

so I have a bar chart that has x-axis type as “date”, I get the first bar and last bar cut in half.所以我有一个 x 轴类型为“日期”的条形图,我将第一个条形图和最后一个条形图切成两半。 I want full bars.我想要完整的酒吧。

Second Problem 2.第二题2。

I want to show hours under every bar at x-axis from 7 AM TO 7PM ( like this ).我想从早上 7 点到晚上 7 点在 x 轴的每个条形下方显示小时数(像这样)。 I am unable to resolve both problems.我无法解决这两个问题。 I have written the code above.我已经写了上面的代码。 Thanks谢谢

consider this link: redirect to the changed code考虑这个链接:重定向到更改的代码

The following changes are made: arrow function has been removed, and the graph plot is assigned to the variable like this进行了以下更改:箭头 function 已被删除,图形 plot 被分配给这样的变量

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

For first problem: use autorange: true , range is ignored对于第一个问题:使用autorange: truerange被忽略

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM