Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Charts: StackedBarSeries with DateTimeAxis
Forum Updated to NodeBB v4.3 + New Features

Qt Charts: StackedBarSeries with DateTimeAxis

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 599 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    markugra
    wrote on last edited by
    #1

    Hi there,

    I was wondering if anyone has ever tried to plot a (Stacked)BarSeries with a DateTimeAxis as x-axis?
    Basically I would like to have something like an AreaSeries over time but with a bar for each time point (each day in my case) also allowing for missing days.
    Starting from the qmlchart example I tried the following (View7.qml):

    import QtQuick 2.0
    import QtCharts 2.0
    
    Item {
        anchors.fill: parent
    
        //![1]
        ChartView {
            title: "Stacked Bar series"
            anchors.fill: parent
            legend.alignment: Qt.AlignBottom
            antialiasing: true
    
            StackedBarSeries {
                id: mySeries
                ValueAxis{
                    id: valuesID
                    min:0
                    max:4
                    Component.onCompleted: {console.log("max:"+ max)}
                    tickCount: 6
                }
                DateTimeAxis{
                    id: datesID
                    tickCount: 6
                    max: {
                        var today = new Date()
                        return today
                    }
                    min: {
                        var daysAgo = new Date()
                        daysAgo.setMinutes( Qt.formatDateTime ( datesID.max, "mm" )  );
                        daysAgo.setHours( Qt.formatDateTime ( datesID.max, "hh" )-24*(datesID.tickCount-1) );
                        return daysAgo
                    }
                }
                axisX: datesID //valuesID//BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
                BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
                BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
                BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
            }
        }
        //![1]
    }
    
    

    However, the chart is empty if I assign mySeries.axisX to datesID. Using the value axis (valuesID) instead, shows the bars at their index position.

    I could probably create a BarCategoryAxis with DateTime-Strings and insert a 0 for missing days in the BarSets, but I doubt that this displays nicely when I want to plot many days and therefore only a few ticks with labels on the x-axis.

    Does any one have a suggestion?

    I would also be open to using other libraries apart from QtCharts (e.g. qCustomPlot, QWT,...), but I want to include the plot in a window together with QtQuick 2 elements which seems to be rather difficult from what I read. But maybe there has been some changes that I am not aware of?

    I'd appreciate any comments, thanks!

    1 Reply Last reply
    2
    • D Offline
      D Offline
      devCool
      wrote on last edited by
      #2

      Were you able to figure this out? I have the same issue.

      1 Reply Last reply
      0

      • Login

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