QChart Multiple Lines with QString as X Axis instead of double values
-
Hi Guys,
I want to create a chart with Dates as X Axis instead of values.
I tried it with category like in this example http://doc.qt.io/qt-5/qtcharts-lineandbar-example.html but the problem is that the Q String arent on the exact Position where the Point of the line is ... because it is for bar charts...
I hope that sb has an idea.This is my code :
Buger->createDefaultAxes(); Buger->axisX()->setTitleText("Time Step"); QStringList categories; categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; QBarCategoryAxis *axisX = new QBarCategoryAxis(); axisX->append(categories); Buger->setAxisX(axisX); Buger->axisY()->setTitleText("Speed [km/s]");
Thanks in advance !
-
I want to create a chart with Dates as X Axis instead of values
Then instead of
QBarCategoryAxis
what aboutQDateTimeAxis
(https://doc.qt.io/qt-5/qdatetimeaxis.html)? -
Thanks for the Solution ... but i have one additional question :
i created now chart with the QDateTime example ...
my Problem now is that it takes random date time values for the x axis ... but i want that it takes exactly the datetimes which i added to the series...any idea ?
QDateTimeAxis *axisX = new QDateTimeAxis; //axisX->setTickCount(AllStepDatesAsQDatetime.size()); axisX->setFormat("MMM:dd:yyyy - hh:dd"); axisX->setTitleText("Date"); axisX-> Buger->addAxis(axisX, Qt::AlignBottom); bugerseries1->attachAxis(axisX);
-
@BadHombre
As you can see from the docs ofQDateTimeAxis
, it has a (settable) number of "ticks", which I imagine correspond to (regulary-spaced) labels, and you cannot make it only produce ticks where you have plotted points. I don't know whether you can override its axis stuff and do your own.If you revert to
QBarCategoryAxis
, I don't know exactly where it places the label text anyway, but in any case everything will be regularly-spaced, which then won't correspond to the actual "gap" between dates.So far as I can see, all the axis-types work by regularly-spaced ticks, I don't think you can alter that or control exactly where the tick/label is placed. Unless, that is, an expert know better....