How to change the interval between tick lables in an axis in plot lines?
- Dominant language
- C++
- Stars
- 6.2k
- Forks
- 693
- PR merge metrics
- No merged PRs in 30d
Description
### Discussed in https://github.com/epezent/implot/discussions/524
Originally posted by **GaganKaranth** October 18, 2023
While checking in the demo plot provided by default, in realtime plot the interval between each tick label in X-axis was 1 second

And in my code I get the interval is for every 50 seconds

This is the abstract code
```
ImPlot::BeginPlot(plotId.c_str(), ImVec2(-1,-1), ImPlotFlags_NoTitle|ImPlotFlags_NoFrame|ImPlotFlags_NoMenus))
{
ImPlot::SetupLegend(ImPlotLocation_NorthWest, ImPlotLegendFlags_NoButtons);
ImPlot::SetupAxes("Minutes", NULL, ImPlotAxisFlags_None, ImPlotAxisFlags_None);
ImPlot::SetupAxisLimits(ImAxis_X1,mPassedTime - mPlotInfo.X_SECOND, mPassedTime, ImGuiCond_Always);
ImPlot::SetupAxisFormat(ImAxis_X1, MetricFormatter, (void*)"min");
float yPadding = abs(mPlotInfo.Y_MAX-mPlotInfo.Y_MIN) * 0.005f;
ImPlot::SetupAxisLimits(ImAxis_Y1, mPlotInfo.Y_MIN-yPadding, mPlotInfo.Y_MAX+yPadding, ImGuiCond_Always);
ImPlot::PlotLine(labelId.c_str(), &mBuffers[i]->Data[0].x, &mBuffers[i]->Data[0].y, mBuffers[i]->Data.size(), ImPlotLineFlags_None, mBuffers[i]->Offset, 2 * sizeof(float));
}
ImPlot::Endplot()
```
And this is the metricformatter to label X-axis
```
int MetricFormatter(double value, char* buff, int size, void* data) {
const char* unit = (const char*)data;
static double v = 60.0;
//if (value < 0) {
// return snprintf(buff, size, "");
//}
if (value == 0) {
return snprintf(buff, size, "0 %s", unit);
}
if (fmod(value, v) == 0) {
return snprintf(buff, size, "%g %s", value / v, unit);
}
return snprintf(buff, size, " ");
}
```
As you can see in the above function I want to convert the values at every 60 seconds to minutes and display it, but the "value" I get in the formatter function is in multiples of 50, I checked it buy printing out the values inside function.
I don't even know why I'm getting the values in multiple of 50s, is it possible to get in multiples of 60s or all values if it matters?
So that the tick label would be like 1 min, 2min ..... and so on
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.