Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can C programming plot a graph?

Status
Not open for further replies.

snee

Junior Member level 2
Joined
Nov 18, 2008
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,459
plot graph c++

How can C programming plot a graph?
Using what function or command?
Thanks
 

graphing in c

The 'standard c' language does not have graphing functions. This will also be very dependent on the operating system or device that will display the graph. This kind of functionality will normally be provided as an additional library or API call depending on the compiler / operating system. I suggest that you provide more details regarding Operating system / compiler / cpu etc.
With 'c' you can always write your own or perhaps find something already written on the net
 

plot graph in c++

snee said:
How can C programming plot a graph?
Using what function or command?
Thanks

Better if u use Mathlab.Or Interface graphic lcd by parallel port ...
 

plot graphs in c

you can plot an ascii graph :)
depends on what you need
yet, better use c++ or even matlab if you need good accuracy ;)
 

graph in c language

hash3d said:
you can plot an ascii graph :)
depends on what you need
yet, better use c++ or even matlab if you need good accuracy ;)

Straight C is as good as C++ for this, but as mentioned it is not part of the standard C language. However if you programming for the Windows OS, there are plenty of functions to create graphics suitable for graphing. I've done this myself in Straight C.

The fuction below draws four traces, (voltages read by an ADC card), and is written in straight C - for Windows. Using miscrosofts visual C compiler
Code:
void drawGraph (HWND hwnd, HDC hdc)
{
	//255-150*(g_dataArrayA[i][j]+1)
	int xAxis[9] = {-180,-150,-120,-90,0,90,120,150,180};
	//float g_yAxis[8] = {0,0.5,1.0,1.5,2.0,2.5,3.0,3.5};
	int i=0;
	HPEN	hPenOld, hPenA, hPenB, hPenC, hPenD;

	MoveToEx(hdc, graphOffset, 0, NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), 0);
	

	MoveToEx(hdc, graphOffset+((180/amount)*(int)floor((16200*amount)/360)), 0, NULL);
	LineTo(hdc, graphOffset+((180/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[7]*scaleData));

	MoveToEx(hdc, graphOffset, (int)(g_yAxis[1]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[1]*scaleData));
	MoveToEx(hdc, graphOffset, (int)(g_yAxis[2]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[2]*scaleData));
	MoveToEx(hdc, graphOffset, (int)(g_yAxis[3]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[3]*scaleData));
	MoveToEx(hdc, graphOffset, (int)(g_yAxis[4]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[4]*scaleData));
	MoveToEx(hdc, graphOffset, (int)(g_yAxis[5]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[5]*scaleData));
	MoveToEx(hdc, graphOffset, (int)(g_yAxis[6]*scaleData), NULL);
	LineTo(hdc, graphOffset+((360/amount)*(int)floor((16200*amount)/360)), (int)(g_yAxis[6]*scaleData));
	hPenA=CreatePen(PS_SOLID,30,RGB(0,255,0));
	hPenB=CreatePen(PS_SOLID,30,RGB(255,0,00));
	hPenC=CreatePen(PS_SOLID,30,RGB(0,0,255));
	hPenD=CreatePen(PS_SOLID,30,RGB(255,255,0));
	hPenOld = SelectObject(hdc, hPenA);



	if (g_i>1 && g_i<=(int)(360/amount))//paint the individual points
	{
		
		MoveToEx(hdc, graphOffset+((g_i-1)*(int)floor((16200*amount)/360)), ((g_aAverage[g_i-1])), NULL);
		SelectObject(hdc, hPenA);
		LineTo(hdc, graphOffset+((g_i)*(int)floor((16200*amount)/360)), (g_aAverage[g_i]));
		MoveToEx(hdc, graphOffset+((g_i-1)*(int)floor((16200*amount)/360)), ((g_bAverage[g_i-1])), NULL);
		SelectObject(hdc, hPenB);
		LineTo(hdc, graphOffset+((g_i)*(int)floor((16200*amount)/360)), ((g_bAverage[g_i])));
		MoveToEx(hdc, graphOffset+((g_i-1)*(int)floor((16200*amount)/360)), ((g_cAverage[g_i-1])), NULL);
		SelectObject(hdc, hPenC);
		LineTo(hdc, graphOffset+((g_i)*(int)floor((16200*amount)/360)), ((g_cAverage[g_i])));
		MoveToEx(hdc, graphOffset+((g_i-1)*(int)floor((16200*amount)/360)), ((g_dAverage[g_i-1])), NULL);
		SelectObject(hdc, hPenD);
		LineTo(hdc, graphOffset+((g_i)*(int)floor((16200*amount)/360)), ((g_dAverage[g_i])));
	}
	else if (g_i>=(int)(360/amount)) //repaints the entire graph so as it is not lost to future repaints
	{
		for (i=1;i<=(int)(360/amount);i++)
		{	
			if (i>1)
			{
				MoveToEx(hdc, graphOffset+((i-1)*(int)floor((16200*amount)/360)), ((g_aAverage[i-1])), NULL);
				SelectObject(hdc, hPenA);
				LineTo(hdc, graphOffset+((i)*(int)floor((16200*amount)/360)), ((g_aAverage[i])));
				MoveToEx(hdc, graphOffset+((i-1)*(int)floor((16200*amount)/360)), ((g_bAverage[i-1])), NULL);
				SelectObject(hdc, hPenB);
				LineTo(hdc, graphOffset+((i)*(int)floor((16200*amount)/360)), ((g_bAverage[i])));
				MoveToEx(hdc, graphOffset+((i-1)*(int)floor((16200*amount)/360)), ((g_cAverage[i-1])), NULL);
				SelectObject(hdc, hPenC);
				LineTo(hdc, graphOffset+((i)*(int)floor((16200*amount)/360)), ((g_cAverage[i])));
				MoveToEx(hdc, graphOffset+((i-1)*(int)floor((16200*amount)/360)), ((g_dAverage[i-1])), NULL);
				SelectObject(hdc, hPenD);
				LineTo(hdc, graphOffset+((i)*(int)floor((16200*amount)/360)), ((g_dAverage[i])));
			}
		}
	}
	SelectObject(hdc, hPenOld);
	DeleteObject(hPenA);
	DeleteObject(hPenB);
	DeleteObject(hPenC);
	DeleteObject(hPenD);
}
 

c plot graph

Or you can use very good OSC_dll programming library
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top