Hey @Annie_Ellenberger ,
If you're running into the issue of duplicate month labels on the X-axis using the lineChart
component, I’d recommend switching over to the Plotly JSON chart instead. It gives you a lot more flexibility in formatting, axis control, and overall customization.
Here’s an example that solves the duplicate month issue by setting the tick mode to one tick per month (dtick: "M1"
) and formatting the date labels to show just the month and year:
return {
"data": [
{
"x": [
"2024-05-01", "2024-05-10", "2024-05-20",
"2024-06-01", "2024-06-15",
"2024-07-01", "2024-07-10"
],
"y": [25, 18, 12, 6, 8, 12, 15],
"type": "scatter",
"mode": "lines+markers",
"fill": "tozeroy",
"name": "Line 1"
},
{
"x": [
"2024-05-01", "2024-05-15",
"2024-06-01", "2024-06-20",
"2024-07-01", "2024-07-15"
],
"y": [10, 4, 1, 3, 5, 7],
"type": "scatter",
"mode": "lines+markers",
"fill": "tozeroy",
"name": "Line 2"
}
],
"layout": {
"title": {
"text": "Monthly Line Chart (one tick per month)",
"x": 0.5
},
"xaxis": {
"type": "date",
"tickformat": "%B %Y",
"tickmode": "linear",
"dtick": "M1",
"tick0": "2024-05-01",
"showline": true,
"linewidth": 1
},
"yaxis": {
"title": "Value"
},
"showlegend": true
}
}
Here’s a quick screenshot for reference: