Wrapper widget around QChartView which provides basic zoom/pan/legend handling stuff
Because I got rid of configuring the QtCharts widget in each of my applications
Add this project to your Qt application as a submodule with:
git submodule add https://github.com/martonmiklos/qt_zoomable_chart_widget.git
Include it into your project by adding the follwing to your .pro file:
include(qt_zoomable_chart_widget/zoomable_chart_widget.pri)
Create you UI with QtDesigner (or Designer plugin in the QtCreator). Add your chart as a QWidget and then promote to the ZoomableChartWidget:
You can access the underlying QtChart object via
ui->whateverIsMyWidgetName->chart()
You can add/remove series,axes do whatever else you do with a QtChart.
There is a zoom mode selector combobox above the chart. I know this is a space wasting thing, I am planning to move this feature to a hamburger style button to the graph area's corner.
You can select 4 zoom modes with it:
- Pan mode: you can drag the graph content with pressed mouse button along the horizontal axes. If you press the Ctrl key you can do panning along the vertical axes.
- Rectangular zoom mode
- You can zoom into the graph contents on the horizontal axis with the mouse wheel. If you press the Ctrl key the zoom will be performed on the vertical axis.
- You can zoom into the graph contents on the vertical axis with the mouse wheel. If you press the Ctrl key the zoom will be performed on the horizontal axis.
You can show/hide series by clicking on the Legend markers. Inspired by the Legend markers Qt example)
Protip: by pressing the Shift you can show/hide multiple series by a single click
When hovering the mouse over the legend markers the respective series line width will be doubled:
You can limit the scroll/zooming ranges of QValueAxes by using RangeLimitedValueAxis.
If you find this feature useful to be included in the Qt itself please comment/vote on this issue.