I have created a QML chart
ChartView {
id: chart
anchors.fill: parent
antialiasing: true
ValueAxis {
id: axisY
tickCount: 3
}
DateTimeAxis {
id: xTime
}
SplineSeries {
id: chartseries
pointsVisible: true
pointLabelsVisible: false
useOpenGL: true
axisX: xTime
axisY: axisY
}
}
I am also appending at the beginning of each month to the chart. Tooltip on tick points are correct. On X axis Qt itself is doing the same as it like . How to adjust it manually
Xaxis->setTickCount(commonmap.size());
QMap<qint64,double>::const_iterator i = commonmap.constBegin();
while (i != commonmap.constEnd())
{
splineseries->append(i.key(),i.value());
++i;
}
I have found an answer to this problem (may not be the right way...But can be solved) Step to achieve the solution -
setMax
date of QDateTimeAxis
.It works Because Qt divides the days between Start date and end date equally and distribute across X axis based ob the tick count .
With the values above in the question will get a chart as shown in the Image
[
Xaxis->setMin(QDateTime::fromMSecsSinceEpoch(commonmap.firstKey()));
Xaxis->setMax(getLastDate());
getLastDate()
{
QDate firstdate =
QDateTime::fromMSecsSinceEpoch(commonmap.lastKey()).date();
int month = firstdate.month();
int day = firstdate.day();
int addday = 0;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
addday = 31- day;
break;
case 4:
case 6:
case 9:
case 11:
addday = 30- day;
break;
case 2:
if(firstdate.isLeapYear(firstdate.year()))
{
addday = 29- day;
}
else
{
addday = 28- day;
}
break;
}
return (QDateTime::fromMSecsSinceEpoch(commonmap.lastKey()).addDays(addday));
}