> Header `ZufyUICharts.h`. `ChartBase` centralizes plot geometry, "nice" ticks, category axis, grid, legend, palette, internal scrollbars, sticky axes, hover/hit, Ctrl-zoom, drag-pan, entrance animation; `BarChart`/`LineChart` implement only `DrawData`.
Minimal example:
```cpp
#include "ZufyUICharts.h"
auto chart = std::make_shared<BarChart>();
chart->AddSeries(L"Sales");
chart->AddCategory(L"Q1"); chart->AddCategory(L"Q2"); chart->AddCategory(L"Q3");
chart->SetSeriesValues(0, { 12.0, 30.0, 22.0 });
chart->SetWidth(420); chart->SetHeight(260); // size comes from the chart itself — set it or give a layout weight
root->AddChild(chart);
```
## ChartBase
```cpp
enum class AText { Left, Center, Right }; enum class AVert { Top, Center };
struct Series { std::wstring name; std::vector<double> values; Color color; };
inline static std::vector<Color> DefaultPalette; // 8 colors
ZSignal<int,int> PointClicked; // (series, category)
ZSignal<int> CategoryClicked; // (category)
// data
void AddCategory(const std::wstring&);
void AddSeries(const std::wstring& name, const std::vector<double>& v = {});
void SetValue(int s, int c, double);
void SetSeriesValues(int s, const std::vector<double>&); // resets + replays entrance animation
void UpdateSeriesValues(int s, const std::vector<double>&); // repaint only, no animation (live)
void ClearData();
int CategoryCount() const; int SeriesCount() const;
// config
void SetPalette(const std::vector<Color>&); void SetSeriesColor(int s, Color);
void SetValueAxisRange(double min, double max); void SetValueAxisAutoRange();
void SetValueTickCount(int n); void SetValueTickStep(double);
void SetValueFormat(int decimals, const std::wstring& prefix=L"", const std::wstring& suffix=L"");
void SetShowGrid(bool); void SetShowVGrid(bool); void SetShowLegend(bool); void SetShowValues(bool);
void SetShowCategoryLabels(bool); void SetLabelFont(const FontSpec&); void SetColors(Color axis, Color grid, Color label);
void SetStickyAxes(bool); // sticky axes (on by default)
void SetAnimationEnabled(bool); void SetAnimationDuration(float);
void SetCategoryWidth(float); void SetPlotHeight(float); void SetFitPlotSize(bool);
void SetReferenceLine(double value, const std::wstring& label=L"", Color c=...); void ClearReferenceLine();
void SetVReferenceLine(int category, const std::wstring& label=L"", Color c=...); void ClearVReferenceLine();
// extension points
virtual void DrawData(ID2D1RenderTarget*) = 0;
virtual void ComputeValueRange(double& lo, double& hi);
virtual void UpdateHover(float,float); virtual void OnDataClick(float,float);
virtual std::wstring HoveredText() const;
```
###block_red_start
**Pitfall**
- a custom `ChartBase` subclass **must call `InitScrollBars()`** (as BarChart/LineChart do) or the internal scrollbars stay null.
- for live data use `UpdateSeriesValues` (no animation replay), not `SetSeriesValues`.
- wheel = Ctrl-zoom (0.4..3) / Shift-horizontal scroll / else vertical; drag pans only after > 4 DIP.
- area-fill baseline is clamped into the visible axis range, so auto-ranged charts don't flood the plot with the bottom band. `LineChart` keeps this off by design.
###block_red_end
- **`Version`**: `SetFillWidth/Height(true)` fills the parent axis when the parent gives a constraint; with no constraint (`avail=FLT_MAX`) and no explicit size it **falls back to the default `420×260`** (since v1.19.4; no longer collapses to 0). Charts default to weight 0 — use `SetFillWidth/Height(true)` or a stretch weight to fill the layout.
## BarChart
```cpp
enum class Orientation { Vertical, Horizontal }; // Horizontal implemented v1.18.0
enum class StackMode { Grouped, Stacked, PercentStacked, Overlapped };
void SetOrientation(Orientation); void SetStackMode(StackMode);
void SetBarGap(float); void SetStackBarRatio(float); void SetGroupGap(float);
void SetCornerRadius(float); void SetBarOutline(float w, Color=...);
void SetBarColor(int s, int c, Color); void SetSelectedCategory(int c);
```
## LineChart
```cpp
enum class Marker { None, Circle, Square };
void SetLineWidth(float); void SetSmooth(bool); void SetDashed(bool);
void SetShowMarkers(bool); void SetMarkerSize(float); void SetMarker(Marker);
void SetAreaFill(bool on, float alpha=0.25f);
```
## PieChart (standalone UIElement)
```cpp
enum class LabelMode { None, Percent, Value, LabelAndPercent };
ZSignal<int> SliceClicked;
void AddSlice(const std::wstring& label, double value, Color = auto);
void Clear(); int SliceCount() const;
void SetDonut(float ratio); // 0=pie, 0.5=donut
void SetStartAngle(float deg); void SetClockwise(bool); void SetSliceGap(float deg);
void SetLabelMode(LabelMode); void SetShowLegend(bool);
void SetZoom(float); float GetZoom() const; // v1.18.0: wheel zoom 0.4..4
bool OnMouseWheel(float,float) override; // draw radius and hit-test share zoom_
void SetAnimationEnabled(bool);
```
###block_red_start
**Pitfall**
- `PieChart` default stretch weight is 0 — needs an explicit size or layout weight.
- labels use leader lines — on the right half, text is left-aligned just after the leader end; on the left half, right-aligned just before it.
###block_red_endCharts
ChartBase, BarChart, LineChart, PieChart (v1.18.0)
Header
ZufyUICharts.h.ChartBasecentralizes plot geometry, "nice" ticks, category axis, grid, legend, palette, internal scrollbars, sticky axes, hover/hit, Ctrl-zoom, drag-pan, entrance animation;BarChart/LineChartimplement onlyDrawData.
Minimal example:
cpp
#include "ZufyUICharts.h"
auto chart = std::make_shared<BarChart>();
chart->AddSeries(L"Sales");
chart->AddCategory(L"Q1"); chart->AddCategory(L"Q2"); chart->AddCategory(L"Q3");
chart->SetSeriesValues(0, { 12.0, 30.0, 22.0 });
chart->SetWidth(420); chart->SetHeight(260); // size comes from the chart itself — set it or give a layout weight
root->AddChild(chart);
ChartBase
cpp
enum class AText { Left, Center, Right }; enum class AVert { Top, Center };
struct Series { std::wstring name; std::vector<double> values; Color color; };
inline static std::vector<Color> DefaultPalette; // 8 colors
ZSignal<int,int> PointClicked; // (series, category)
ZSignal<int> CategoryClicked; // (category)
// data
void AddCategory(const std::wstring&);
void AddSeries(const std::wstring& name, const std::vector<double>& v = {});
void SetValue(int s, int c, double);
void SetSeriesValues(int s, const std::vector<double>&); // resets + replays entrance animation
void UpdateSeriesValues(int s, const std::vector<double>&); // repaint only, no animation (live)
void ClearData();
int CategoryCount() const; int SeriesCount() const;
// config
void SetPalette(const std::vector<Color>&); void SetSeriesColor(int s, Color);
void SetValueAxisRange(double min, double max); void SetValueAxisAutoRange();
void SetValueTickCount(int n); void SetValueTickStep(double);
void SetValueFormat(int decimals, const std::wstring& prefix=L"", const std::wstring& suffix=L"");
void SetShowGrid(bool); void SetShowVGrid(bool); void SetShowLegend(bool); void SetShowValues(bool);
void SetShowCategoryLabels(bool); void SetLabelFont(const FontSpec&); void SetColors(Color axis, Color grid, Color label);
void SetStickyAxes(bool); // sticky axes (on by default)
void SetAnimationEnabled(bool); void SetAnimationDuration(float);
void SetCategoryWidth(float); void SetPlotHeight(float); void SetFitPlotSize(bool);
void SetReferenceLine(double value, const std::wstring& label=L"", Color c=...); void ClearReferenceLine();
void SetVReferenceLine(int category, const std::wstring& label=L"", Color c=...); void ClearVReferenceLine();
// extension points
virtual void DrawData(ID2D1RenderTarget*) = 0;
virtual void ComputeValueRange(double& lo, double& hi);
virtual void UpdateHover(float,float); virtual void OnDataClick(float,float);
virtual std::wstring HoveredText() const;
Pitfall
- a custom
ChartBasesubclass must callInitScrollBars()(as BarChart/LineChart do) or the internal scrollbars stay null. - for live data use
UpdateSeriesValues(no animation replay), notSetSeriesValues. - wheel = Ctrl-zoom (0.4..3) / Shift-horizontal scroll / else vertical; drag pans only after > 4 DIP.
- area-fill baseline is clamped into the visible axis range, so auto-ranged charts don't flood the plot with the bottom band.
LineChartkeeps this off by design.
Version:SetFillWidth/Height(true)fills the parent axis when the parent gives a constraint; with no constraint (avail=FLT_MAX) and no explicit size it falls back to the default420×260(since v1.19.4; no longer collapses to 0). Charts default to weight 0 — useSetFillWidth/Height(true)or a stretch weight to fill the layout.
BarChart
cpp
enum class Orientation { Vertical, Horizontal }; // Horizontal implemented v1.18.0
enum class StackMode { Grouped, Stacked, PercentStacked, Overlapped };
void SetOrientation(Orientation); void SetStackMode(StackMode);
void SetBarGap(float); void SetStackBarRatio(float); void SetGroupGap(float);
void SetCornerRadius(float); void SetBarOutline(float w, Color=...);
void SetBarColor(int s, int c, Color); void SetSelectedCategory(int c);
LineChart
cpp
enum class Marker { None, Circle, Square };
void SetLineWidth(float); void SetSmooth(bool); void SetDashed(bool);
void SetShowMarkers(bool); void SetMarkerSize(float); void SetMarker(Marker);
void SetAreaFill(bool on, float alpha=0.25f);
PieChart (standalone UIElement)
cpp
enum class LabelMode { None, Percent, Value, LabelAndPercent };
ZSignal<int> SliceClicked;
void AddSlice(const std::wstring& label, double value, Color = auto);
void Clear(); int SliceCount() const;
void SetDonut(float ratio); // 0=pie, 0.5=donut
void SetStartAngle(float deg); void SetClockwise(bool); void SetSliceGap(float deg);
void SetLabelMode(LabelMode); void SetShowLegend(bool);
void SetZoom(float); float GetZoom() const; // v1.18.0: wheel zoom 0.4..4
bool OnMouseWheel(float,float) override; // draw radius and hit-test share zoom_
void SetAnimationEnabled(bool);
Pitfall
PieChartdefault stretch weight is 0 — needs an explicit size or layout weight.- labels use leader lines — on the right half, text is left-aligned just after the leader end; on the left half, right-aligned just before it.