Unsolved Qt Charts: StackedBarSeries with DateTimeAxis
-
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!
-
Were you able to figure this out? I have the same issue.