Fluent-Qt

Charts

LineChart

Shows how values change over time or order with lines.

Example

LineChart: Response time

Usage

Response time

Write points and labels into a ChartModel and call setModel(). addSeries() adds a second series for comparison.

#include <FluentQt/Charts.h>
using namespace fluent::charts;

auto* chart = new LineChart(this);
chart->setObjectName("chartPresentation");
chart->setMinimumHeight(420);
chart->setTitle("Response time");
chart->setSubtitle("Milliseconds · last 7 days");
auto* model = new ChartModel(chart);
model->setName("Primary");
const QStringList labels = {"Mon",        "Mon, 04:48", "Mon, 09:36", "Mon, 14:24", "Mon, 19:12", "Tue",
     "Tue, 04:48", "Tue, 09:36", "Tue, 14:24", "Tue, 19:12", "Wed",        "Wed, 04:48",
     "Wed, 09:36", "Wed, 14:24", "Wed, 19:12", "Thu",        "Thu, 04:48", "Thu, 09:36",
     "Thu, 14:24", "Thu, 19:12", "Fri",        "Fri, 04:48", "Fri, 09:36", "Fri, 14:24",
     "Fri, 19:12", "Sat",        "Sat, 04:48", "Sat, 09:36", "Sat, 14:24", "Sat, 19:12",
     "Sun"};
model->setPoints(
    {{0, 27},  {1, 32},  {2, 28},  {3, 34},  {4, 30},  {5, 36},  {6, 34},  {7, 32},
     {8, 41},  {9, 39},  {10, 37}, {11, 42}, {12, 46}, {13, 43}, {14, 40}, {15, 46},
     {16, 42}, {17, 47}, {18, 52}, {19, 48}, {20, 54}, {21, 59}, {22, 56}, {23, 61},
     {24, 57}, {25, 60}, {26, 58}, {27, 64}, {28, 59}, {29, 66}, {30, 62}},
    labels);
chart->setModel(model);
auto* secondary = new ChartModel(chart);
secondary->setName("Secondary");
secondary->setPoints(
    {{0, 14},  {1, 18},  {2, 16},  {3, 20},  {4, 17},  {5, 22},  {6, 20},  {7, 18},
     {8, 25},  {9, 23},  {10, 22}, {11, 26}, {12, 29}, {13, 27}, {14, 25}, {15, 28},
     {16, 26}, {17, 31}, {18, 34}, {19, 30}, {20, 35}, {21, 41}, {22, 38}, {23, 42},
     {24, 39}, {25, 43}, {26, 40}, {27, 44}, {28, 41}, {29, 46}, {30, 43}}, labels);
chart->addSeries(secondary);
chart->setValueSuffix(" ms");
chart->setYRange(0, 80);

fluent::charts::LineChart

Inherits ChartView

Line chart widget backed by a ChartModel.

Constructors

Inherited from fluent::charts::ChartView

Properties

ChartType chartType
Read chartType()Write setChartType()Notify chartTypeChanged()
QString title
Read title()Write setTitle()Notify titleChanged()
QString subtitle
Read subtitle()Write setSubtitle()Notify subtitleChanged()
QString valueSuffix

Unit suffix appended to value readouts (e.g. " ms" or "%").

Read valueSuffix()Write setValueSuffix()Notify valueSuffixChanged()
QString centerText
Read centerText()Write setCenterText()Notify centerTextChanged()
QString centerCaption
Read centerCaption()Write setCenterCaption()Notify centerCaptionChanged()
bool loading

Shows a loading state while data is prepared externally.

Read isLoading()Write setLoading()Notify loadingChanged()
bool autoYRange
Read isAutoYRange()Notify yRangeChanged()
bool legendVisible
Read isLegendVisible()Write setLegendVisible()Notify legendVisibleChanged()
int maximumPointCount
Read maximumPointCount()Write setMaximumPointCount()Notify maximumPointCountChanged()
int maximumFrameRate
Read maximumFrameRate()Write setMaximumFrameRate()Notify maximumFrameRateChanged()
bool autoRange
Read isAutoRange()Notify xRangeChanged()

Methods

void setModel(ChartModel* model)

Sets a single chart model (still managed by the caller); pass nullptr to clear.

bool addSeries(ChartModel* model)

Adds a series model (up to 32, caller-managed); duplicates are ignored. Pie and Donut only render seriesModel(0); prefer setModel() for those types.

void setChartType(ChartType type)

Changes the chart type on a generic ChartView; dedicated subclasses keep a fixed type.

QString valueSuffix() const

Unit suffix appended to value readouts (e.g. " ms" or "%").

void setValueSuffix(const QString& suffix)

Unit suffix appended to value readouts (e.g. " ms" or "%").

bool isLoading() const

Shows a loading state while data is prepared externally.

void setLoading(bool loading)

Shows a loading state while data is prepared externally.

void setYRange(double minimum, double maximum)

Sets a finite increasing Y range (e.g. [0, 100]); invalid ranges are ignored.

void setMaximumPointCount(int count)

Sets the sampled point budget in [512, 65536], capped by viewport width.

void setMaximumFrameRate(int rate)

Throttles model updates to [1, 60] Hz; hidden charts pause updates.

void setXRange(double minimum, double maximum)

Sets a finite increasing X range; invalid ranges are ignored.

void setCurrentPoint(int series, int row)

Moves the data cursor to a series row; pass -1 to clear.

int renderedPointCount() const

Sampled point count from the most recent paint pass.

QImage exportImage(double scale = 1.0)

Exports the chart image at the given scale (without hover cursor or focus outline); call on the GUI thread.

QByteArray exportPng(double scale = 1.0)

Encodes exportImage() as PNG bytes, returning empty on failure.

QByteArray exportCsv(bool visibleRangeOnly = false) const

Exports raw model rows as UTF-8 CSV (columns: series, name, x, y, label, unit); call on the GUI thread. Pass visibleRangeOnly = true to restrict Cartesian charts to the current X range.

void copyImage(double scale = 1.0)

Copies the chart PNG to the clipboard and emits imageCopied().

void copyData(bool visibleRangeOnly = false)

Copies exported CSV rows to the clipboard and emits dataCopied(). Must be called on the GUI thread (off-thread calls emit dataCopied(false)).

Signals

void valueSuffixChanged(const QString& suffix)

Unit suffix appended to value readouts (e.g. " ms" or "%").

void loadingChanged(bool loading)

Shows a loading state while data is prepared externally.

void rangeActivated(int series, int first, int last)

Emitted when a displayed point or bucket [first, last) is activated.

Enumerations

enum ChartType
  • Line
  • Area
  • Bar
  • HorizontalBar
  • Pie
  • Donut
  • Scatter
  • Sparkline
Inherited from fluent::FluentElement

Methods

static void setTheme(Theme theme)

Updates the global theme and notifies active FluentElement instances.

static void setThemeDeferred(Theme theme)

Schedules a visible-first batched theme refresh without blocking the current interaction.

static Theme currentTheme()

Returns the currently active global theme.

static bool themeUsesDarkAppearance(Theme theme)

Returns whether a theme uses dark-backed chrome and material tokens.

static void refreshTheme()

Re-broadcasts the current theme to repaint after a design-token change.

static int themeGeneration()

Monotonic counter bumped on every theme change, for staleness checks.

Theme effectiveTheme() const

Resolves the theme used by this element, honoring an inherited QWidget override.

bool effectiveThemeUsesDarkAppearance() const

Returns whether this element's effective theme uses dark-backed chrome.

bool setThemeOverrides(const QJsonObject& overrides)

Replaces this element's sparse color, radius, and font token overrides.

QJsonObject themeOverrides() const

Returns this element's authored overrides.

void clearThemeOverrides()

Restores all token fields to global theme defaults.

const Colors& themeColorsRef() const

Non-copying access to the active color set for hot paint paths.

Material::AcrylicToken themeAcrylic() const

Material, elevation, and adaptive layout tokens.

QColor themeBackdrop(bool active) const

Window-chrome backdrop color for the given activation state.

virtual void onThemeUpdated()

Called after the global theme changes.

Enumerations

enum Theme

Global visual theme used when resolving design tokens.

  • Light = 0
  • Dark = 1
  • HighContrast = 2

Types and aliases

struct Colors

Design token snapshots returned to components.

Inherited from fluent::QMLPlus

Methods

AnchorLayout::Anchors* anchors()

Returns mutable anchors for the QWidget host.

void setState(const QString& name)

Applies a registered state by name, or restores the default state when @p name is empty. Unknown names are ignored, and existing bindings resume when leaving the state.

void addState(const QMLState& state)

Registers or replaces a named state definition; replacing the active state applies it immediately.

void evaluateStates()

Reevaluates state conditions in registration order and activates the first match, or the default state if none match. Also runs automatically when dependency properties notify; derived states using extend inherit ancestor changes unless cyclic or missing.

QMLPlusRuntime* runtime()

Returns the lazily created state observer owned by this host.

void setAnchors(const AnchorLayout::Anchors& anchors)

Replaces all host anchors and invalidates the parent layout.

void resetAnchors()

Clears all host anchors and invalidates the parent layout.

void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)

Binds @p sourceProp on @p source to @p targetProp on this QWidget host via PropertyBinder::bind().

void addTransition(const StateTransition& transition)

Registers a state transition in precedence order.

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

Sets the default animation used when @p propertyName is written via writeProperty() or a binding. Explicit StateTransition rules take precedence; direct C++ setter calls are not animated.

void clearBehavior(const char* propertyName)

Removes the default animation for future managed writes.

bool writeProperty(const char* propertyName, const QVariant& value)

Writes a host property through Behavior without removing its binding.

Qt base class docs: QWidget