Skip to content

Custom X axis label for the first grid line #717

Not planned

Description

@erkanisuf

Hello i would like to add (string , possibly icon) where the red line is.
Screenshot 2021-08-03 at 10 51 29

My options are like this:

                                        xAxes: [{
							type: "time",
							position: "bottom",
							time: {
								displayFormats: {
									"year": "YYYY"
								},
								tooltipFormat: "MM-YYYY",
								unit: "year"
							},
							ticks: {
								offset: false,
								maxTicksLimit: 8,
								callback: (value, index) => {
									if (index === 0) {
										return "custom item"
									} else {
										return value
									}
								}
							}
						}]

I pushed a "fake data with year f.ex 1930" to the dataset and used ticks callback to change if the index is 0 with custom value but then it start to display all the years between like this: (which i don`t want).
Screenshot 2021-08-03 at 11 08 27

Then i changed the "fake data year to 2016" and it looks like this :
Screenshot 2021-08-03 at 11 20 23
I want something similar to this but the starting point should be as i showed in the first screenshot.
Would appreciate any tips how i can achieve that.

Activity

  1. Arantiryo commented on May 14, 2022

    @Arantiryo
    Collaborator

    Hi @erkanisuf 👋

    Have you considered passing labels separately like in this example?

  2. dangreen commented on Nov 30, 2026

    @dangreen
    Collaborator

    Closing: this is about how Chart.js itself behaves or is configured, while react-chartjs-2 passes data, options and plugins to Chart.js as they are. The Chart.js docs cover it: https://www.chartjs.org/docs/latest/ If it turns out to be a bug, please report it to Chart.js: https://github.com/chartjs/Chart.js/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions