Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart Multiple Lines with QString as X Axis instead of double values
Forum Updated to NodeBB v4.3 + New Features

QChart Multiple Lines with QString as X Axis instead of double values

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BadHombre
    wrote on 1 Dec 2017, 20:43 last edited by
    #1

    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 !

    J 1 Reply Last reply 1 Dec 2017, 21:49
    0
    • B BadHombre
      1 Dec 2017, 20:43

      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 !

      J Offline
      J Offline
      JonB
      wrote on 1 Dec 2017, 21:49 last edited by
      #2

      @BadHombre

      I want to create a chart with Dates as X Axis instead of values

      Then instead of QBarCategoryAxis what about QDateTimeAxis (https://doc.qt.io/qt-5/qdatetimeaxis.html)?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BadHombre
        wrote on 2 Dec 2017, 11:38 last edited by
        #3

        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);
        
        J 1 Reply Last reply 4 Dec 2017, 09:13
        0
        • B BadHombre
          2 Dec 2017, 11:38

          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);
          
          J Offline
          J Offline
          JonB
          wrote on 4 Dec 2017, 09:13 last edited by
          #4

          @BadHombre
          As you can see from the docs of QDateTimeAxis, 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....

          1 Reply Last reply
          0

          1/4

          1 Dec 2017, 20:43

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved