Visualizing functions with Charts
Until now, we have discussed how to build charts using datasets, which include raw data information such as sales figures, market shares, or usage trends. However, we don’t have to use datasets to create charts, as functions can also perform as a data source for our charts.
For example, we may want to display a normal distribution line graph next to our BarMark chart. We could also create an education app that displays mathematical functions such as circles or a sinus function.
To do that, we need to use a different type of chart called plot.
The Charts framework has two types of plots – LinePlot
and AreaPlot
. Let’s see an example of LinePlot
showing a graph for a sinus function:
Chart { LinePlot(x:"x", y:"y") { x in return sin(x) } }
In this (very!) short code example, we added a LinePlot...