OpenXLSX 1.10.0
Loading...
Searching...
No Matches
XLChart.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLCHART_HPP
2#define OPENXLSX_XLCHART_HPP
3
4#include "OpenXLSX-Exports.hpp"
5#include "XLConstants.hpp"
6#include "XLXmlFile.hpp"
7
8#include <optional>
9#include <string>
10#include <string_view>
11
12namespace OpenXLSX
13{
59
61
63
64 enum class XLLineDashType {
65 Unset,
66 Solid,
67 Dot,
68 Dash,
69 LgDash,
70 DashDot,
73 SysDash,
74 SysDot,
76 };
77
80 High,
81 Low,
82 None
83 };
84
95 class XLWorksheet;
96 class XLCellRange;
97
98 enum class XLErrorBarDirection { X, Y };
99
100 enum class XLErrorBarType { Both, Minus, Plus };
101
103
105
107
108 enum class XLAxisCrosses { AutoZero, Min, Max };
109
110 class OPENXLSX_EXPORT XLChartSeries
111 {
112 public:
113 XLChartSeries() = default;
114 explicit XLChartSeries(const XMLNode& node);
115
116 XLChartSeries& setTitle(std::string_view title);
119
124 XLChartSeries& setColor(std::string_view hexRGB);
125
131 XLChartSeries& setDataPointColor(uint32_t pointIdx, std::string_view hexRGB);
132
139 XLChartSeries& setDataLabels(bool showValue, bool showCategoryName = false, bool showPercent = false);
140
147
151 XLChartSeries& addTrendline(XLTrendlineType type, std::string_view name = "", uint8_t order = 2, uint8_t period = 2);
152
157
160
161 private:
162 XMLNode m_node;
163 };
164
166 {
167 std::string name;
168 uint32_t row{1};
169 uint32_t col{1};
172
173 XLChartAnchor() = default;
174 XLChartAnchor(std::string_view n, uint32_t r, uint32_t c, XLDistance w, XLDistance h) : name(n), row(r), col(c), width(w), height(h)
175 {}
176 };
177
178 class OPENXLSX_EXPORT XLAxis
179 {
180 public:
181 XLAxis() = default;
182 explicit XLAxis(const XMLNode& node);
183
184 void setTitle(std::string_view title);
185
186 void setMinBounds(double min);
188
189 void setMaxBounds(double max);
191
196 void setMajorUnit(double unit);
197
202 void setMinorUnit(double unit);
203
208 void setLogScale(double base);
209
214 void setDateAxis(bool isDateAxis);
215
221
227
232 void setCrossesAt(double value);
233
234 void setMajorGridlines(bool show);
235 void setMinorGridlines(bool show);
236
242 void setNumberFormat(std::string_view formatCode, bool sourceLinked = false);
243
245
246 private:
247 XMLNode m_node;
248 };
249
250 class OPENXLSX_EXPORT XLChart final : public XLXmlFile
251 {
252 public:
256 XLChart() : XLXmlFile(nullptr) {}
257
262 explicit XLChart(XLXmlData* xmlData);
263
268 XLChart(const XLChart& other) = default;
269
273 XLChart(XLChart&& other) noexcept = default;
274
278 ~XLChart() = default;
279
283 XLChart& operator=(const XLChart& other) = default;
284
288 XLChart& operator=(XLChart&& other) noexcept = default;
289
297 const XLCellRange& values,
298 std::string_view title = "",
299 std::optional<XLChartType> targetChartType = std::nullopt,
300 bool useSecondaryAxis = false);
302 const XLCellRange& values,
303 const XLCellRange& categories,
304 std::string_view title = "",
305 std::optional<XLChartType> targetChartType = std::nullopt,
306 bool useSecondaryAxis = false);
307 XLChartSeries addSeries(std::string_view valuesRef,
308 std::string_view title = "",
309 std::string_view categoriesRef = "",
310 std::optional<XLChartType> targetChartType = std::nullopt,
311 bool useSecondaryAxis = false);
312
321 addBubbleSeries(std::string_view xValRef, std::string_view yValRef, std::string_view sizeRef, std::string_view title = "");
322
324 const XLCellRange& xValues,
325 const XLCellRange& yValues,
326 const XLCellRange& sizes,
327 std::string_view title = "");
328
332 void setTitle(std::string_view title);
333
337 void setStyle(uint8_t styleId);
338
343
347 [[nodiscard]] XLAxis xAxis() const;
348
352 [[nodiscard]] XLAxis yAxis() const;
353
354 [[nodiscard]] XLAxis axis(std::string_view position) const;
355
359 void setShowDataLabels(bool showValue, bool showCategory = false, bool showPercent = false);
360
364 void setSeriesSmooth(uint32_t seriesIndex, bool smooth);
365
369 void setSeriesMarker(uint32_t seriesIndex, XLMarkerStyle style);
370
375 void setGapWidth(uint32_t percent);
376
381 void setOverlap(int32_t percent);
382
387 void setHoleSize(uint8_t percent);
388
395 void setRotation(uint16_t x, uint16_t y, uint16_t perspective = 30);
396
401 void setPlotAreaColor(std::string_view hexRGB);
402
407 void setChartAreaColor(std::string_view hexRGB);
408
409 void setShowDataTable(bool showTable, bool showKeys = false);
410
411 private:
412 friend class XLDocument;
413 void initXml(XLChartType type = XLChartType::Bar);
414 [[nodiscard]] uint32_t seriesCount() const;
415 };
416} // namespace OpenXLSX
417
418#endif // OPENXLSX_XLCHART_HPP
Definition XLXmlParser.hpp:84
Definition XLChart.hpp:179
void setMinorGridlines(bool show)
void setNumberFormat(std::string_view formatCode, bool sourceLinked=false)
Set the number format for axis tick labels.
void setDateAxis(bool isDateAxis)
Convert this axis to a date axis or back to a category axis.
void setTitle(std::string_view title)
void setMinorUnit(double unit)
Set the minor unit (interval between minor tick marks) for the axis.
XLAxis(const XMLNode &node)
void setOrientation(XLAxisOrientation orientation)
Set the orientation of the axis (normal or reverse).
void setTickLabelPosition(XLAxisTickLabelPosition position)
void setCrosses(XLAxisCrosses crosses)
Set the axis crossing mode.
void setCrossesAt(double value)
Set the axis to cross at a specific value.
void setMaxBounds(double max)
void setMajorGridlines(bool show)
void setMajorUnit(double unit)
Set the major unit (interval between major tick marks) for the axis.
void setLogScale(double base)
Set the axis to use a logarithmic scale.
void setMinBounds(double min)
XLAxis()=default
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:30
Definition XLChart.hpp:111
XLChartSeries & setColor(std::string_view hexRGB)
Set the fill and line color of this data series.
XLChartSeries & setMarkerStyle(XLMarkerStyle style)
XLChartSeries & setDataLabels(bool showValue, bool showCategoryName=false, bool showPercent=false)
Enable and configure data labels for this series.
XLChartSeries & setLineDash(XLLineDashType dashType)
XLChartSeries & setDataPointColor(uint32_t pointIdx, std::string_view hexRGB)
Override the color of a single data point within this series.
XLChartSeries & setLineWidth(double points)
XLChartSeries & setDataLabelsFromRange(const XLWorksheet &wks, const XLCellRange &range)
Set the data labels for this series to come from a worksheet range.
XLChartSeries & setSmooth(bool smooth)
XLChartSeries & addTrendline(XLTrendlineType type, std::string_view name="", uint8_t order=2, uint8_t period=2)
Add a trendline to this series.
XLChartSeries & setTitle(std::string_view title)
XLChartSeries(const XMLNode &node)
XLChartSeries & addErrorBars(XLErrorBarDirection direction, XLErrorBarType type, XLErrorBarValueType valType, double value=0.0)
Add error bars to this series.
Definition XLChart.hpp:251
XLChartSeries addSeries(const XLWorksheet &wks, const XLCellRange &values, std::string_view title="", std::optional< XLChartType > targetChartType=std::nullopt, bool useSecondaryAxis=false)
Add a data series to the chart.
void setPlotAreaColor(std::string_view hexRGB)
Fill the chart plot area with a solid color.
void setStyle(uint8_t styleId)
Set the built-in chart style ID (1–48).
void setRotation(uint16_t x, uint16_t y, uint16_t perspective=30)
Set the rotation of a 3D chart.
void setShowDataLabels(bool showValue, bool showCategory=false, bool showPercent=false)
Configure the display of data labels on the chart.
XLChartSeries addBubbleSeries(const XLWorksheet &wks, const XLCellRange &xValues, const XLCellRange &yValues, const XLCellRange &sizes, std::string_view title="")
void setHoleSize(uint8_t percent)
Set the size of the hole in a doughnut chart.
XLChartSeries addSeries(std::string_view valuesRef, std::string_view title="", std::string_view categoriesRef="", std::optional< XLChartType > targetChartType=std::nullopt, bool useSecondaryAxis=false)
void setLegendPosition(XLLegendPosition position)
Set the legend position or hide it.
XLChart(XLXmlData *xmlData)
Constructor from XLXmlData.
XLChart & operator=(const XLChart &other)=default
Copy Assignment Operator.
XLChart(const XLChart &other)=default
Copy Constructor.
XLAxis axis(std::string_view position) const
XLChartSeries addSeries(const XLWorksheet &wks, const XLCellRange &values, const XLCellRange &categories, std::string_view title="", std::optional< XLChartType > targetChartType=std::nullopt, bool useSecondaryAxis=false)
XLChart(XLChart &&other) noexcept=default
Move Constructor.
void setShowDataTable(bool showTable, bool showKeys=false)
XLAxis xAxis() const
Get the X-axis (typically bottom category axis).
void setChartAreaColor(std::string_view hexRGB)
Fill the outermost chart space background with a solid color.
void setOverlap(int32_t percent)
Set the overlap between bars/columns within a cluster.
void setTitle(std::string_view title)
Set the chart title.
void setGapWidth(uint32_t percent)
Set the gap width between bar/column clusters.
void setSeriesMarker(uint32_t seriesIndex, XLMarkerStyle style)
Set the marker style for a specific series.
~XLChart()=default
Destructor.
XLChart & operator=(XLChart &&other) noexcept=default
Move Assignment Operator.
XLAxis yAxis() const
Get the Y-axis (typically left value axis).
XLChartSeries addBubbleSeries(std::string_view xValRef, std::string_view yValRef, std::string_view sizeRef, std::string_view title="")
Add a bubble chart series with explicit X, Y, and size ranges.
void setSeriesSmooth(uint32_t seriesIndex, bool smooth)
Set whether a specific series should be rendered with a smooth line.
XLChart()
Constructor.
Definition XLChart.hpp:256
Definition XLConstants.hpp:32
static XLDistance Pixels(uint32_t px)
Definition XLConstants.hpp:35
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:82
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:120
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:68
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition IZipArchive.hpp:18
XLErrorBarDirection
Definition XLChart.hpp:98
XLAxisOrientation
Definition XLChart.hpp:106
XLAxisTickLabelPosition
Definition XLChart.hpp:78
XLMarkerStyle
Definition XLChart.hpp:62
XLLineDashType
Definition XLChart.hpp:64
XLTrendlineType
Definition XLChart.hpp:104
XLChartType
Definition XLChart.hpp:14
@ ScatterLineMarker
Scatter with straight lines and markers.
@ ScatterMarker
Scatter with markers only, no lines.
@ ScatterLine
Scatter with straight lines, no markers.
@ ScatterSmoothMarker
Scatter with smooth lines and markers.
@ Bubble
Bubble chart (needs addBubbleSeries)
@ ScatterSmooth
Scatter with smooth lines, no markers.
XLErrorBarValueType
Definition XLChart.hpp:102
XLAxisCrosses
Definition XLChart.hpp:108
XLErrorBarType
Definition XLChart.hpp:100
XLLegendPosition
Definition XLChart.hpp:60
Definition XLChart.hpp:166
uint32_t row
Definition XLChart.hpp:168
std::string name
Definition XLChart.hpp:167
XLChartAnchor(std::string_view n, uint32_t r, uint32_t c, XLDistance w, XLDistance h)
Definition XLChart.hpp:174
XLDistance width
Definition XLChart.hpp:170
XLDistance height
Definition XLChart.hpp:171
uint32_t col
Definition XLChart.hpp:169