使用C Visual Studio创建一个绘图图

Create a plot graphs with c++ visual studio

本文关键字:一个 绘图 Visual Studio 创建 使用      更新时间:2023-10-16

y轴将自动缩放,具体取决于降低功能的值。

void mouseHandleCordinate(double val){
  // include graph function.
}

所以我想在时间上创建情节图表。x轴表示时间,y表示值超过函数的值。我如何在上面的图形函数上创建。

始终将数据传递到void mouseHandleCordinate(double val)函数中。例如:

val >>> 2.1,3,1,6,7,5.5,0,9,5,6,7,3.6,2,5,6,7,8,1,2,3,4 >> represent double val
Time>>> 21,20,19,18,17,......., 4,3,2,1 second

不确定我会得到您的要求,但看起来您想创建连续函数的下表,诸如:

const int N=21; // number of samples
const double t0=21.0,t1=1.0; // start,end times
const double val[N]={ 2.1,3,1,6,7,5.5,0,9,5,6,7,3.6,2,5,6,7,8,1,2,3,4 };
double f(double t) // nearest
 {
 t = (t-t0)/(t1-t0); // time scaled to <0,1>
 t*= (N-1); // time scaled to <0,N) .. index in table
 int ix=t; // convert to closest index in val[]
 if ((ix<0)||(ix>=N)) return 0.0; // handle undefined times
 return val[ix]; // return closest point in val[]
 }

这将为您提供最近的邻居样式功能值。如果您需要一些更好的使用线性或立方体或更好的插值:

double f(double t) // linear
 {
 t = (t-t0)/(t1-t0); // time scaled to <0,1>
 t*= (N-1); // time scaled to <0,N) .. index in table
 int ix=t; // convert to closest index in val[]
 if ((ix<0)||(ix>=N)) return 0.0; // handle undefined times
 if (ix==N-1) return val[ix]; // return closest point in val[] if on edge
 // linear interpolation
 t = t-floor(t); // distance of time between ix and ix+1 points scaled to <0,1>
 return val[ix]+(val[ix+1]-val[ix])*t; // return linear interpolated value
 }

现在解决您的问题:

void mouseHandleCordinate(double mx) // mouse x coordinate in [pixels] I assume
 {
 double t,x,y,x0,y0
 // plot
 x=0;
 y=f(view_start_time)
 for (t=view_start_time;t<=view_end_time;t+=(view_end_time-view_start_time)/view_size_in_pixels,x0=x,x++)
  {
  y0=y; y=f(t); 
  // render line x0,y0,x,y
  }
 // mouse highlight
 t = view_start_time+((view_end_time-view_start_time)*mx/view_size_in_pixels);
 x = mx;
 y = f(t);
 // render point x,y ... for example with circle r = 16 pixels
 }

其中:
view_start_time是绘图视图中左左最像素的时间
view_end_time是您情节视图中最正确的像素的时间
view_size_in_pixels是图视图的[像素]中的x分辨率

[注意]

i直接在SO编辑器中代码,因此可能会有错别字...希望您在某些油漆事件中调用mouseHandleCordinate,而不是在鼠标移动中,这只能安排重新粉刷订单...您也应该以与x刻度相似的方式添加Y视图比例...

...

有关更多信息,请参见:

  • 如何产生多点线性插值?