mermaid/docs/syntax/xyChart.md

195 lines
7.7 KiB
Markdown
Raw Normal View History

2023-09-02 17:18:11 +02:00
> **Warning**
>
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
>
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/xyChart.md](../../packages/mermaid/src/docs/syntax/xyChart.md).
# XY Chart
> In the context of mermaid-js, the XY chart is a comprehensive charting module that encompasses various types of charts that utilize both x-axis and y-axis for data representation. Presently, it includes two fundamental chart types: the bar chart and the line chart. These charts are designed to visually display and analyze data that involve two numerical variables.
> It's important to note that while the current implementation of mermaid-js includes these two chart types, the framework is designed to be dynamic and adaptable. Therefore, it has the capacity for expansion and the inclusion of additional chart types in the future. This means that users can expect an evolving suite of charting options within the XY chart module, catering to various data visualization needs as new chart types are introduced over time.
## Example
```mermaid-example
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
```
```mermaid
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
```
## Syntax
> **Note**
2023-09-19 17:39:31 +02:00
> All text values that contain only one word can be written without `"`. If a text value has many words in it, specifically if it contains spaces, enclose the value in `"`
2023-09-02 17:18:11 +02:00
### Orientations
The chart can be drawn horizontal or vertical, default value is vertical.
2023-09-02 17:18:11 +02:00
2024-03-23 07:09:02 +01:00
```
xychart-beta horizontal
...
```
2023-09-02 17:18:11 +02:00
2023-09-19 17:48:06 +02:00
### Title
2023-09-02 17:18:11 +02:00
The title is a short description of the chart and it will always render on top of the chart.
#### Example
2024-03-23 07:09:02 +01:00
```
xychart-beta
title "This is a simple example"
...
```
2023-09-02 17:18:11 +02:00
> **Note**
2023-09-20 16:27:48 +02:00
> If the title is a single word one no need to use `"`, but if it has space `"` is needed
2023-09-02 17:18:11 +02:00
### x-axis
The x-axis primarily serves as a categorical value, although it can also function as a numeric range value when needed.
#### Example
2024-03-23 07:09:02 +01:00
1. `x-axis title min --> max` x-axis will function as numeric with the given range
2. `x-axis "title with space" [cat1, "cat2 with space", cat3]` x-axis if categorical, categories are text type
2023-09-02 17:18:11 +02:00
### y-axis
The y-axis is employed to represent numerical range values, it cannot have categorical values.
2023-09-02 17:18:11 +02:00
#### Example
2024-03-23 07:09:02 +01:00
1. `y-axis title min --> max`
2. `y-axis title` it will only add the title, the range will be auto generated from data.
2023-09-02 17:18:11 +02:00
> **Note**
> Both x and y axis are optional if not provided we will try to create the range
### Line chart
A line chart offers the capability to graphically depict lines.
#### Example
2024-03-23 07:09:02 +01:00
1. `line [2.3, 45, .98, -3.4]` it can have all valid numeric values.
2023-09-02 17:18:11 +02:00
### Bar chart
A bar chart offers the capability to graphically depict bars.
#### Example
2024-03-23 07:09:02 +01:00
1. `bar [2.3, 45, .98, -3.4]` it can have all valid numeric values.
2023-09-02 17:18:11 +02:00
#### Simplest example
The only two things required are the chart name (`xychart-beta`) and one data set. So you will be able to draw a chart with a simple config like
2023-09-02 17:18:11 +02:00
2024-03-23 07:09:02 +01:00
```
xychart-beta
line [+1.3, .6, 2.4, -.34]
```
2023-09-02 17:18:11 +02:00
## Chart Configurations
| Parameter | Description | Default value |
| ------------------------ | ---------------------------------------------- | :-----------: |
| width | Width of the chart | 700 |
| height | Height of the chart | 500 |
| titlePadding | Top and Bottom padding of the title | 10 |
| titleFontSize | Title font size | 20 |
| showTitle | Title to be shown or not | true |
| xAxis | xAxis configuration | AxisConfig |
| yAxis | yAxis configuration | AxisConfig |
| chartOrientation | 'vertical' or 'horizontal' | 'vertical' |
2023-09-02 17:18:11 +02:00
| plotReservedSpacePercent | Minimum space plots will take inside the chart | 50 |
### AxisConfig
2023-09-03 10:08:47 +02:00
| Parameter | Description | Default value |
| ------------- | ------------------------------------ | :-----------: |
| showLabel | Show axis labels or tick values | true |
| labelFontSize | Font size of the label to be drawn | 14 |
| labelPadding | Top and Bottom padding of the label | 5 |
| showTitle | Axis title to be shown or not | true |
| titleFontSize | Axis title font size | 16 |
| titlePadding | Top and Bottom padding of Axis title | 5 |
| showTick | Tick to be shown or not | true |
| tickLength | How long the tick will be | 5 |
| tickWidth | How width the tick will be | 2 |
| showAxisLine | Axis line to be shown or not | true |
| axisLineWidth | Thickness of the axis line | 2 |
2023-09-02 17:18:11 +02:00
## Chart Theme Variables
> **Note**
2023-09-02 17:45:21 +02:00
> Themes for xychart resides inside xychart attribute so to set the variables use this syntax
> %%{init: { "themeVariables": {"xyChart": {"titleColor": "#ff0000"} } }}%%
2023-09-02 17:18:11 +02:00
| Parameter | Description |
| ---------------- | --------------------------------------------------------- |
| backgroundColor | Background color of the whole chart |
| titleColor | Color of the Title text |
| xAxisLabelColor | Color of the x-axis labels |
| xAxisTitleColor | Color of the x-axis title |
| xAxisTickColor | Color of the x-axis tick |
| xAxisLineColor | Color of the x-axis line |
| yAxisLabelColor | Color of the y-axis labels |
| yAxisTitleColor | Color of the y-axis title |
| yAxisTickColor | Color of the y-axis tick |
| yAxisLineColor | Color of the y-axis line |
| plotColorPalette | String of colors separated by comma e.g. "#f3456, #43445" |
2023-09-02 17:18:11 +02:00
## Example on config and theme
```mermaid-example
2023-09-07 10:01:52 +02:00
---
config:
xyChart:
width: 900
height: 600
themeVariables:
xyChart:
titleColor: "#ff0000"
---
2023-09-02 17:18:11 +02:00
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
```
```mermaid
2023-09-07 10:01:52 +02:00
---
config:
xyChart:
width: 900
height: 600
themeVariables:
xyChart:
titleColor: "#ff0000"
---
2023-09-02 17:18:11 +02:00
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
```