How to draw a plot chart using visual studio c++
18,983
1) checkout and install Microsoft vcpkg to new folder (see 1-step instruction here: https://github.com/Microsoft/vcpkg)
2) vcpkg.exe install plplot from vcpkg folder
3) vcpkg.exe integrate project will give you instruction to add plplot to your MSVC project
4) paste this instruction to the Nuget Console:
5) after you paste and project reloads you can try this code:
#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;
}
and you get:
tested on MSVC2015
Author by
Wpiumi pabasara
Updated on June 05, 2022Comments
-
Wpiumi pabasara almost 2 years
I want to create a plot chart using visual studio with c++ code. The chart should be based on two axis. "x" axis display the time and "y" axis display the array data. array data have 100 elements and one data read in one second. How do I implement the code using any other graph library?
-
Sembei Norimaki almost 3 years"Paste this instruction in the NugetConsole"... and no instruction is provided.
-
Stepan Yakovenko almost 3 years@SembeiNorimaki look at 3)