Multiple x axis on the bottom of chart

VascoCC

I'm trying to show multiple x axis on the bottom of my chart. I started to add the axis with layout.xaxis.position to show them stacked but they start getting over the chart. Then I set layout.margin.pad to 50 and I got the result I wanted for the first axis only.

Is there a way to do this for the remaining ones? Or is this a bug?

var layout = {
  xaxis: {
    fixedrange: true,
    autoexpand: false
  },
  xaxis2: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.1
  },
  xaxis3: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.2
  },
  yaxis: {
    fixedrange: true,
    zeroline: false,
    rangemode: 'tozero'
  },
  showlegend: false,
  autosize: false,
  width: 450,
  height: 220,
  margin: {
    l: 10,
    r: 10,
    b: 60,
    t: 10,
    pad: 40
  }
};

Chart Image with mad paint skills.

Chart Image

Codepen example here

Naren Murali

I checked your codepen, the problem is simply that position cannot be set to a negative value, hence you can move the axes up, but now down. I have two solutions for you, it involves positioning the axes using the ticklength, as a sort of hack, please refer the below example, implement it and let me know if your issue is resolved!

var data = JSON.parse('[{"name":"Atual","x":["May 28","May 29","May 30","May 31","Jun 01","Jun 02","Jun 03"],"y":[115.4,122.4,102.3,105.1,28.9,29.6,114.2]},{"name":"Atual-1","xaxis":"x2","x":["Jun 04","Jun 05","Jun 06","Jun 07","Jun 08","Jun 09","Jun 10"],"y":[69.6,71.1,78.9,72.5,24.5,25.2,69.2]},{"name":"Atual-2","xaxis":"x3","x":["Jun 11","Jun 12"],"y":[0.08,0]},{"name":"Atual 77777","xaxis":"x3","x":["Jun 11","Jun 12"],"y":[109.9,2.9]},{"name":"Atual-3","xaxis":"x4","x":["Jun 11","Jun 12"],"y":[8.6,0.2]},{"name":"Atual 2","xaxis":"x4","x":["Jun 11","Jun 12"],"y":[0.06,0]}]');

var layout = {
  xaxis: {
    fixedrange: true,
    autoexpand: false,
    visible: false
  },
  xaxis2: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.1,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    gridcolor: "#000000"
  },
  xaxis3: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.2,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    gridcolor: "#000000"
  },
  xaxis4: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    gridcolor: "#000000"
  },
  yaxis: {
    fixedrange: true,
    zeroline: false,
    rangemode: 'tozero'
  },
  showlegend: false,
  autosize: false,
  width: 450,
  height: 220,
  margin: {
    l: 30,
    r: 0,
    b: 70,
    t: 0,
    pad: 0
  }
};

var layout2 = {
  xaxis: {
    fixedrange: true,
    autoexpand: false,
    visible: false
  },
  xaxis2: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.1,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    tickcolor: "#eee"
  },
  xaxis3: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0.2,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    tickcolor: "#eee"
  },
  xaxis4: {
    fixedrange: true,
    domain: [0,1],
    anchor: 'free',
    overlaying: 'x',
    position: 0,
    layer: "below traces",
    ticklen: 30,
    tickwidth: 1,
    ticks: "outside",
    tickcolor: "#eee"
  },
  yaxis: {
    fixedrange: true,
    zeroline: false,
    rangemode: 'tozero'
  },
  showlegend: false,
  autosize: false,
  width: 450,
  height: 220,
  margin: {
    l: 30,
    r: 0,
    b: 70,
    t: 0,
    pad: 0
  }
};

Plotly.newPlot('myDiv', data, layout, {displayModeBar: false, showTips: false, staticPlot: false});

Plotly.newPlot('myDiv2', data, layout2, {displayModeBar: false, showTips: false, staticPlot: false});
<script src="https://cdn.plot.ly/plotly-latest.js"></script>
<div id="myDiv" style="width: 480px; height: 400px;">
<div id="myDiv2" style="width: 480px; height: 400px;">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Hide bottom x axis in horizontal bar chart?

MPAndroidChart how to set x-axis to the bottom of the chart?

How to remove the Chart.js x Axis bottom line?

Seaborn BarPlot invert y axis and keep x axis on bottom of chart area

Can't view multiple bars on the x axis - vue-chart

how to create a bar chart in python with multiple x-axis

How to animate a d3 js v4 bar chart from bottom(x axis) to up?

how to show x-axis values at top instead of bottom in kendo chart

Echarts Bar Chart Axis Label on Top and Bottom

Highchart draw rows at bottom of the chart align with axis

Add x-axis to matplotlib with multiple y-axis line chart

How to show x-axis dotted labels on y-axis for multiple column chart in hightchart js

Highchart Line chart – data series with multiple axis - 2nd series placed in the middle of X axis

How to create a stacked JavaFX Chart, with multiple Y Axis and common X Axis

How to create Stacked Line Chart in chartjs Multiple Y Axis and common X Axis

compress x axis in high chart

chart x-axis numbering

Line chart not aligned with x axis

Waffle chart with time on x axis

Excel Chart X Axis Values

Filter in X axis, within a chart

Chart X Axis wrong labels

ChartJs: X Axis labels cutting at bottom

Setting x axis label to bottom in openpyxl

Multi-series chart - time (year) interval x-axis overlaying multiple years of data

MS Chart X Axis label repeated - showing multiple points for a single item [Range Bar]

how to get multiple x-axis labels for a react-chartjs-2 chart

Highcharts renders opposite y axis lower than chart's bottom

Change X-axis Line Chart flutter