Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a plot chart using visual studio c++

Tags:

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?

like image 306
Wpiumi pabasara Avatar asked Jun 09 '17 01:06

Wpiumi pabasara


1 Answers

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:

enter image description here

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:

enter image description here

tested on MSVC2015

like image 162
Stepan Yakovenko Avatar answered Oct 14 '22 03:10

Stepan Yakovenko