3.3.7 Plot Same Column in One Graph


Version Info

Minimum Origin Version Required: Origin 8 SR0

Example

This example shows how to plot the same column in a graph, first part using scatter, and second part using line.

void plot_partial_data()
{
	Worksheet wks;
	wks.Create("origin");
	wks.SetSize(50,2);
	int nXCol = 0; 
	int nYCol = 1;
	Dataset dx(wks, nXCol);
	dx.Data(1,50);
	dx *= 0.05;
	Dataset dy(wks, nYCol);
	dy.Normal(50);
	dy += 1.2;

	int nR1 = 20;
	DataRange dr;
	dr.Add("X", wks, 0, nXCol, nR1, nXCol);
	dr.Add("Y", wks, 0, nYCol, nR1, nYCol);
	
	GraphPage gp;
	gp.Create("origin", CREATE_HIDDEN);
	GraphLayer gl = gp.Layers();
	gl.AddPlot(dr, IDM_PLOT_SCATTER);
	
	// add 2nd plot of same range
	DataRange dr2;
	dr2.Add("X", wks, nR1, nXCol, -1, nXCol);
	dr2.Add("Y", wks, nR1, nYCol, -1, nYCol);
	gl.AddPlot(dr2, IDM_PLOT_LINE);
	
	gl.Rescale();
	gp.SetShow();
}