图形中的条形图 [英] Bar Graph in Graphics

查看:71
本文介绍了图形中的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多编程论坛中都曾问过这个问题,但仍然没有答案..请帮助..
该程序实际上是用于在C ++图形中绘制直方图.但是我无法获得条形图.

这是代码...

I have asked this question in many programming forum but still no answer.. please help..
This program is actually for drawing a Histogram in C++ graphics. But i am not able to get the bar graph.

Here is the code...

#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int gdriver=DETECT,gmode,errorcode,n;
cout<<"Enter the number of data:\n";
cin>>n;
double a[10];
double b[10];
double c[10];
for(int i=0;i<n;i++)
{
cout<<"Enter the lower boundary a["<<i<<"]=";
cin>>a[i];
cout<<"Enter the upper boundary b["<<i<<"]=";
cin>>b[i];
cout<<"Enter the frequency c["<<i<<"]=";
cin>>c[i];
}
clrscr();
cout<<"class interval"<<"\tfrequency\n";
for(i=0;i<n;i++)
{
cout<<"\t\n"<<a[i]<<"-"<<b[i]<<"\t\t"<<c[i];
cout<<"\n\n";
}
getch();
/*Initialise graphics & local variables*/
initgraph(&gdriver,&gmode,"c:\\tc\\");
setbkcolor(0);
setcolor(3);
line(120,400,520,400);
line(120,20,120,400);
for(i=140;i<=520;i+=20)
{
putpixel(1,400,4);
}
outtextxy(1,420,"x");
for(i=20;i<=400;i+=20)
putpixel(120,i,4);
outtextxy(100,20,"y");
outtextxy(110,420,"(0,0) scale 10cm for each dot");
int j=0,k=0;
setcolor(2);
char pattern[2]={0x00,0x70};
setfillpattern(pattern,12);
j=120;
k=130;
for(i=0;i<n;i++,j=j+a[i],k=k+b[i])
{
bar3d(120+2*a[i],400-10*c[i],120+2*b[i],400,2,6);
}
getch();
}

推荐答案

此循环看起来可能是错误的,因为在putpixel调用中未使用变量i:
This loop looks as if it might be wrong, since the variable i isn''t used in the putpixel call:
for(i=140;i<=520;i+=20)
{
    putpixel(1,400,4);
}



不过,最好对这个问题有更多的了解,您是否可以发布到目前为止您的程序绘制的(错误的)输出?



It would be good to know a bit more about the problem though, could you maybe post the (wrong) output your program draws so far?


这篇关于图形中的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆