Example 13. Graphs




DolphinDB supports various chart types, such as line, pie, column, bar and scatter.


We can use function plot for basic graphing. The system supports various chart types, such as line, pie, column, bar and scatter.


The syntax of function plot is


plot(input data[, labels[, titles[, chartType]]])


We can use a vector, tuple, matrix, or table as the input data.



Line chart 1: plot a table


x=0.1*(1..100)

y=0.1*(100..1)

t=table(x,y)

plot(t)


the graph above can also be generated by plot(t[`x`y]).



Line chart 2: plot a matrix


plot([sin,cos](x),x,"cos and sin curve")



note that function names are used as series names, and we specify data labels and the graph title.



Line chart 3: plot a vector


plot(cumsum(x) as cumsumX, 2012.10.01+1..100, "cumulative sum of x")



cumsumX is used as the series name



Line chart 4: plot a tuple


plot([1..10 as x, 10..1 as y], 1..10)



x and y are used as the series names



Example 5: plot a bar graph


plot(1..5 as value, `IBM`MSFT`GOOG`XOM`C, `rank, BAR)




Example 6: plot a column graph


plot(99 128 196 210 312 as sales, `IBM`MSFT`GOOG`XOM`C, `sales, COLUMN)




Example 7: plot a pie graph


plot(99 128 196 210 312 as sales, `IBM`MSFT`GOOG`XOM`C, `sales, PIE)




Example 8: scatter plot


x=rand(1.0, 1000);

y=x+norm(0.0:0.2, 1000);

plot(x, y, ,SCATTER)



Download source code here.