Open taibai123abc opened 1 month ago
Hope that helps ... but it seems an example for all this is missing ...
Thanks for your response and it is useful for me. But when tick label is too long, a natural idea is to make it able to change lines, but when I use ui->plot->getXAxis()->setTickDateTimeFormat("yyyy/MM/dd\nHH:mm:ss");
, it has no effect.
All labels/text in JKQTPlotter use Latex-markup ... try using \ (I.e. in c-code "...\\..." instead of \n
The documentation of JkQtMathText has a large list of available LaTeX : https://jkriege2.github.io/JKQtPlotter/group__jkqtmathtext__supportedlatex.html
I hava tried "\", but it didn't work.
Could you post a code-snippet?
Of course i can. I use the following code to read data from a file:
QFile file(fileName);
if (!fileName.isEmpty())
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Failed to open the file.";
return;
}
QTextStream infile(&file);
QString line;
QVector<double> temp_points;
int i = 0;
QVector<double> tempX;
QVector<double> tempY;
while (!infile.atEnd())
{
QString line = infile.readLine();
QStringList parts;
if (line.contains(" ")) parts = line.split(" ");
else if (line.contains(",")) parts = line.split(",");
QString dataAndTimeString = parts[0] + " " + parts[1];
dateAndTime.push_back(QDateTime::fromString(dataAndTimeString, "yyyy/MM/dd HH:mm:ss").toUTC().toMSecsSinceEpoch());
squeezeData.push_back(parts[2].toDouble());
}
The datas of the file like the picture: Then i use the dateAndTime and squeezeData to draw a time-height graph.
JKQTPDatastore* ds = ui->plot->getDatastore();
QVector<double> partXData = dateAndTime.mid(0, ui->numSpinBox->value());
QVector<double> partYData = squeezeData.mid(0, ui->numSpinBox->value());
ui->plot->addGraph(graph);
size_t colDate = ds->addCopiedColumn(partXData, "date");
size_t colSq = ds->addCopiedColumn(partYData, "squeeze");
graph->setXColumn(colDate);
graph->setYColumn(colSq);
graph->setLineStyle(Qt::SolidLine);
graph->setSymbolType(static_cast<JKQTPGraphSymbols>(0));
graph->setTitle(QObject::tr("height"));
ui->plot->getXAxis()->setTickLabelType(JKQTPCALTdatetime);
ui->plot->getXAxis()->setAxisLabel("dataTime");
ui->plot->getXAxis()->setTickDateTimeFormat("yyyy/MM/dd HH:mm:ss");
ui->plot->getXAxis()->setTickLabelFontSize(5);
ui->plot->getXAxis()->setTickSpacing(2);
ui->plot->zoomToFit();
ui->plot->show();
but the "yyyy/MM/dd HH:mm:ss" is too long to make the tick label too sparse or overlaped. So i want to convert "yyyy/MM/dd HH:mm:ss" to two lines. I tried "yyyy/MM/dd\HH:mm:ss" or "yyyy/MM/dd\nHH:mm:ss", but it dosen't works. Maybe the JKQTPlotter dosen't have the function? I know the QCustomPlot has the function and it is useful. Maybe JKQTPlotter should have the function too?
try using ui->plot->getXAxis()->setTickDateTimeFormat("yyyy/MM/dd\\HH:mm:ss");
This will end up as a string "yyyy/MM/dd\HH:mm:ss" after the compiler has resolved the c-escapes "\" -> '\' And the newline ist \ in LaTeX
I am sorry, i spell error in last response.I have triedyyyy/MM/dd\\HH:mm:ss
and yyyy/MM/dd\nHH:mm:ss
, but it dosen't works.
As you can see in the picture, the tick labels will overlap when the tick labels are long. So how to control axis tick interval?