Logarithmic Axis Example▲
Running the Example▲
To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.
Using Logarithmic Value Axes▲
Create a QLineSeries instance and add some data to it.
QLineSeries *
series =
new
QLineSeries();
*
series &
lt;&
lt; QPointF(1.0
, 1.0
) &
lt;&
lt; QPointF(2.0
, 73.0
) &
lt;&
lt; QPointF(3.0
, 268.0
) &
lt;&
lt; QPointF(4.0
, 17.0
)
&
lt;&
lt; QPointF(5.0
, 4325.0
) &
lt;&
lt; QPointF(6.0
, 723.0
);
To present the data on the chart we need a QChart instance. Add the series to it, hide the legend and set the title of the chart.
QChart *
chart =
new
QChart();
chart-&
gt;addSeries(series);
chart-&
gt;legend()-&
gt;hide();
chart-&
gt;setTitle("Logarithmic axis example"
);
Create the axes. Add them to the chart and attach to the series.
QValueAxis *
axisX =
new
QValueAxis();
axisX-&
gt;setTitleText("Data point"
);
axisX-&
gt;setLabelFormat("%i"
);
axisX-&
gt;setTickCount(series-&
gt;count());
chart-&
gt;addAxis(axisX, Qt::
AlignBottom);
series-&
gt;attachAxis(axisX);
QLogValueAxis *
axisY =
new
QLogValueAxis();
axisY-&
gt;setTitleText("Values"
);
axisY-&
gt;setLabelFormat("%g"
);
axisY-&
gt;setBase(8.0
);
axisY-&
gt;setMinorTickCount(-
1
);
chart-&
gt;addAxis(axisY, Qt::
AlignLeft);
series-&
gt;attachAxis(axisY);
Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer.
QChartView *
chartView =
new
QChartView(chart);
chartView-&
gt;setRenderHint(QPainter::
Antialiasing);
The chart is ready to be shown.
QMainWindow window;
window.setCentralWidget(chartView);
window.resize(800
, 600
);
window.show();