Wpi*_*ara 5 c++ graph visual-studio
我想使用带有 C++ 代码的 Visual Studio 创建一个绘图图表。图表应基于两个轴。“x”轴显示时间,“y”轴显示阵列数据。数组数据有 100 个元素,一秒内读取一个数据。如何使用任何其他图形库实现代码?
1) 签出 Microsoft vcpkg 并将其安装到新文件夹(请参阅此处的一步说明: https: //github.com/Microsoft/vcpkg)
2) vcpkg.exe从 vcpkg 文件夹安装 plplot
3) vcpkg.exe 集成项目将指导您将 plplot 添加到 MSVC 项目
4)将此指令粘贴到Nuget控制台:
5)粘贴并重新加载项目后,您可以尝试以下代码:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include "plplot\plstream.h"
using namespace std;
const int NSIZE = 101;
int main(int argc, char ** argv) {
PLFLT x[NSIZE], y[NSIZE];
PLFLT xmin = 0., xmax = 1., ymin = 0., ymax = 100.;
int i;
for (i = 0; i < NSIZE; i++) {
x[i] = (PLFLT)(i) / (PLFLT)(NSIZE - 1);
y[i] = ymax * x[i] * x[i];
}
auto pls = new plstream();
plsdev("wingcc");
pls->init();
pls->env(xmin, xmax, ymin, ymax, 0, 0);
pls->lab("x", "y=100 x#u2#d", "Simple PLplot demo of a 2D line plot");
pls->line(NSIZE, x, y);
delete pls;
}
Run Code Online (Sandbox Code Playgroud)
你得到:
在MSVC2015上测试
几年前我回答了一个非常相似的问题......有一个简单、直接且可编译的示例: 图形表示 - 数据分布
显然,该图表与您需要的图表不同。但您可以修改它,以便使用 C++ 绘制任何您想要的内容,然后制作任何图表。
归档时间: |
|
查看次数: |
16945 次 |
最近记录: |