Sales Chart in C
#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "stdlib.h"
#define P 5
typedef struct coordinate
{
int x,y;
}PT;
int margin=10;
int d8[P],d9[P],interval;
int mp[P],cb;
int labellength=24,dataoffset=18;
PT pt[P];
PT txtpos;
void FunBC(int data[P],int);
void main()
{
int gd=DETECT,gm,i,c,r,k=0;
clrscr();
printf("Enter Data Point Max 400");
printf("\n\nEnter Month Sales Detail For Year 2008");
r=5;
for(i=1;i<=P;i++)
{
start1 :
gotoxy(1,r);
printf("x[%d]",i);
scanf("%d",&d8[i]);
if(k>d8[i] || d8[i]>400)
{
gotoxy(1,r);
printf(" ");
goto start1;
}
k=d8[i];
r+=2;
}
clrscr();
r=5;
k=0;
printf("Enter Data Point Max 400");
printf("\n\nEnter Month Sales Detail For Year 2009");
for(i=1;i<=P;i++)
{
start2:
gotoxy(1,r);
printf("y[%d]",i);
scanf("%d",&d9[i]);
if(k>d9[i] || d9[i]>400)
{
gotoxy(1,r);
printf(" ");
goto start2;
}
k=d9[i];
r+=2;
}
initgraph(&gd,&gm,"");
setcolor(5);
outtextxy(260,10,"Sales Chart");
outtextxy(450,15,"- 2008");
setcolor(6);
outtextxy(450,25,"- 2009");
line(30,20,30,450);
line(30,450,580,450);
outtextxy(5,400,"50");
outtextxy(5,350,"100");
outtextxy(5,300,"150");
outtextxy(5,250,"200");
outtextxy(5,200,"250");
outtextxy(5,150,"300");
outtextxy(5,100,"350");
outtextxy(5,50,"400");
outtextxy(130,455,"Jan");
outtextxy(230,455,"Feb");
outtextxy(330,455,"Mar");
outtextxy(430,455,"Apr");
outtextxy(530,455,"May");
cb=getmaxy()+38;
interval=(540-margin)/P;
FunBC(d8,5);
FunBC(d9,6);
getch();
closegraph();
}
void FunBC(int data[P],int a)
{
int i,k=30;
for(i=1;i<=P;i++)
{
pt[i].y=cb-dataoffset-data[i]-49;
}
pt[0].y=450;
for(i=0;i<=P-1;i++)
{
setcolor(a);
line(k,pt[i].y,k+100,pt[i+1].y);
k+=100;
}
}