The Data Chart extension can be used to visualize your data. When you use it, you can import data sets, input data in batches, or collect and generate data in real time through blocks, and it can display data in tables, line charts, bar charts, dual-axis charts, or pie charts.
Let's have a try.
Select Panda on the Sprites tab and click + Add at the bottom of Data Chart.
Let's make a line chart to show the temperature of Shenzhen in a week.
(1) Drag the Data Chart blocks open data chart window and set chart title ( ) to the Scripts area, and name the chart Temperature of the Week.
(2) Drag the Data Chart block set chart type to ( ) to the Scripts area and choose line chart from the drop-down list box.
(3) Drag the Data Chart block set axis name: x () y ( ) to the Scripts area and set the x axis name to Day and y axis name to Temperature.
(4) Enter the data. Let's enter the following data to generate a line chart.
(5) Drag the Data Chart block input data to ( ): x ( ) y ( ) to the Scripts area. The temperature data of each day includes the highest and lowest temperature. Enter the data for Monday as follows.
(6) Right-click the block and choose Duplicate to quickly add 12 input data to ( ): x ( ) y ( ) blocks. Enter the temperature data of Tuesday to Sunday.
(7) Drag the Events block when green flag clicked to the Scripts area and drop it on the top of the other blocks.
You can choose to display the data in bar or pie charts. You can also choose to view the data in a table.
The dual-axis chart is a special chart type can be used to display multiple data groups. The data of these data groups may be recorded in different units but can share the same x axis.
Based on the highest and lowest temperature of the week, we can analyze the relation between the temperature and humidity.
The unit of humidity data is percentage (%), and that of temperature is degree centigrade (℃). Therefore, these data can't be displayed in a one-axis coordinate system.
You can use a dual-axis chart to display these data.
As shown in the preceding figure, the humidity data is displayed in a bar chart, corresponding to the y axis on the right. The temperature data is displayed in a line chart, corresponding to the y axis on the left. The humidity and temperature data share the same x axis.
You can configure a dual-axis chart in mBlock 5 as follows (based on the preceding temperature example):
1. Set the title of the y axis on the right.
2. Specify which data groups are to be displayed on the y axis on the left, and which on the y axis on the right.
The following dual-axis chart displays the temperature and humidity of the week.
It may be difficult to compare and analyze some data when the difference between the data is not obvious. When this happens, you can scale the chart to make the difference more obvious in one of the following ways:
1. Click the zoom-in/zoom-out button in the upper right corner to zoom in the window.
2. Use the mouse wheel on your PC, gestures on your touch panel, or your finger in the app to drag the chart to scale or move some data. In a dual-axis chart, you can also control the scaling by dragging a bar on the side.
In addition to using blocks to collect and generate data in real time, you can also import data sets in batches.
On the Data Table tab, click Import, select a .csv file from your local disk, and click Open.
After you close the data chart window, the data you have input in the chart is not automatically deleted. To delete the data, you need to use the clear data( ) block. As shown in the following figure, you can delete the data before you input some other data.