|
| 1 | +# Charts and graphs |
| 2 | + |
| 3 | +Charts and graphs are visual representations of data that are used to simplify complex information and make it easier to understand. They can help highlight key insights and provide a quick summary of data that would otherwise be difficult to interpret. Charts and graphs come in different forms, such as bar graphs, line graphs, pie charts, scatter plots, and more, each suited for different types of data and analytical purposes.  |
| 4 | + |
| 5 | +Openblocks allows you to insert multiple forms of charts and graphs into your apps to satisfy your needs in different use cases. |
| 6 | + |
| 7 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-1.gif" alt=""><figcaption></figcaption></figure> |
| 8 | + |
| 9 | +## UI mode |
| 10 | + |
| 11 | +### Data format |
| 12 | + |
| 13 | +In UI mode, the **Chart** component supports presenting data stored as an array of JS objects. Each object field corresponds to a column in tabular format. The objects in the following array contain three fields: `date`, `fruit`, and `count`. |
| 14 | + |
| 15 | +```json |
| 16 | +[ |
| 17 | + { "date": "2022-03-01", "fruit": "apple", "count": 4 }, |
| 18 | + { "date": "2022-03-01", "fruit": "banana", "count": 6 }, |
| 19 | + { "date": "2022-04-01", "fruit": "grape", "count": 10 }, |
| 20 | + { "date": "2022-04-01", "fruit": "apple", "count": 3 }, |
| 21 | + { "date": "2022-04-01", "fruit": "banana", "count": 2 } |
| 22 | +] |
| 23 | +``` |
| 24 | + |
| 25 | +You can also use JS code in `{{}}` to reference data from other components or queries, or to transform data to meet specific needs. |
| 26 | + |
| 27 | +For example, the query result of `query1` is as follows. |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "date": [ |
| 32 | + "2022-03-01", |
| 33 | + "2022-03-01", |
| 34 | + "2022-04-01", |
| 35 | + "2022-04-01", |
| 36 | + "2022-04-01" |
| 37 | + ], |
| 38 | + "fruit": ["apple", "banana", "grape", "apple", "banana"], |
| 39 | + "count": [4, 6, 10, 3, 2] |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +You can transform it using transformer `transformer1` with the following JS code. |
| 44 | + |
| 45 | +```javascript |
| 46 | +let dates = query1.data.date |
| 47 | +let fruits = query1.data.fruit |
| 48 | +let counts = query1.data.count |
| 49 | +let result = [] |
| 50 | +for (let i = 0; i < dates.length; i++) { |
| 51 | + result.push( {'date': dates[i], 'fruit': fruits[i], 'count': counts[i]} ) |
| 52 | +} |
| 53 | +return result; |
| 54 | +``` |
| 55 | + |
| 56 | +Then reference the value of the transformer `{{transformer1.value}}` as the data for the chart. |
| 57 | + |
| 58 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-2.PNG" alt=""><figcaption></figcaption></figure> |
| 59 | + |
| 60 | +### Chart type |
| 61 | + |
| 62 | +Openblocks supports four types of charts: bar chart, line chart, scatter chart, and pie chart. You can select the chart type in **Properties** > **Data** > **Chart type**. You can also customize the layout and style of your chart in **Properties** tab. |
| 63 | + |
| 64 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-3.png" alt=""><figcaption></figcaption></figure> |
| 65 | + |
| 66 | +### X-axis |
| 67 | + |
| 68 | +Bar charts, line charts, and pie charts map values to categorical variables. Thus, in such charts, the X-axis usually shows non-numeric data—for example, date or department. |
| 69 | + |
| 70 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-4.png" alt=""><figcaption></figcaption></figure> |
| 71 | + |
| 72 | +By default, Openblocks automatically detects the X-axis data and its type. You can also manually select one among "Category axis", "Value axis", "Time axis", or "Log axis". For detailed information, see [X axis type](https://echarts.apache.org/en/option.html#xAxis.type). |
| 73 | + |
| 74 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-5.png" alt=""><figcaption></figcaption></figure> |
| 75 | + |
| 76 | +### Chart series |
| 77 | + |
| 78 | +In most types of charts, the **Chart series** (Y-axis) presents numeric values for the categories on X-axis. By default, Openblocks populates all numeric fields to Y-axis. You can hide unnecessary fields in **Properties** > **Chart series**. |
| 79 | + |
| 80 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-6.png" alt=""><figcaption></figcaption></figure> |
| 81 | + |
| 82 | +## Echarts JSON |
| 83 | + |
| 84 | +Apart from the built-in charts and graphs, you can also plot your data with [Apache ECharts](https://echarts.apache.org/en/index.html), an open-source JS visualization library. You only need to complete the **Configuration** > **Option** field in JSON format. For detailed information, see [ECharts docs](https://echarts.apache.org/en/option.html#title) and [ECharts examples](https://echarts.apache.org/examples/en/index.html). |
| 85 | + |
| 86 | +For an instance of using Echarts, see [Stacked Area Chart](https://cloud.openblocks.dev/apps/63779dd6c54c5224c70ea537/view). |
| 87 | + |
| 88 | +<figure><img src="../../.gitbook/assets/charts-and-graphs-7.png" alt=""><figcaption></figcaption></figure> |
| 89 | + |
| 90 | +If you need more configuration options for charts, contact our customer service on the homepage. |
0 commit comments