我想使用带有 C++ 代码的 Visual Studio 创建图表。图表应基于两个轴。 “x”轴显示时间,“y”轴显示数组数据。数组数据有 100 个元素和一个数据在一秒钟内读取。如何使用任何其他图形库实现代码?
最佳答案
1) 结帐并将 Microsoft vcpkg 安装到新文件夹(请参阅此处的 1 步说明: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;
}
你得到:
在 MSVC2015 上测试
关于c++ - 如何使用visual studio c++绘制图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44448010/