C# 缩放/取消缩放和点抽取
情况: 我有一个图表和三个图表区域,它们通过AxisViewChanged方法在视图、缩放和光标中对齐,该方法的作用如下:C# 缩放/取消缩放和点抽取,c#,mschart,C#,Mschart,情况: 我有一个图表和三个图表区域,它们通过AxisViewChanged方法在视图、缩放和光标中对齐,该方法的作用如下: if (e.Axis == ax1) { ax2.ScaleView.Size = ax1.ScaleView.Size; ax2.ScaleView.Position = ax1.ScaleView.Position; ax3.ScaleView.Size = ax1.S
if (e.Axis == ax1)
{
ax2.ScaleView.Size = ax1.ScaleView.Size;
ax2.ScaleView.Position = ax1.ScaleView.Position;
ax3.ScaleView.Size = ax1.ScaleView.Size;
ax3.ScaleView.Position = ax1.ScaleView.Position;
min = (int)ax1.ScaleView.ViewMinimum;
max = (int)ax1.ScaleView.ViewMaximum;
}
if (e.Axis == ax2)
{
....
它在两种情况下都非常有效:当我放大/缩小或滚动时
问题:
问题是我的图形源是由很多点组成的,在最坏的情况下,我们讨论的是360000个样本。有了这么多的样本,当我用光标在点周围移动并尝试显示带有值的工具提示时,交互质量会崩溃并变得不可用(即使设置了快速线)。
因此,我尝试实施一种简单的抽取算法来减少显示点的数量:
void draw_graph(int start, int end)
{
double fract_value = 0;
int int_value = 0;
int num_saples_selected = end - start;
if(num_saples_selected <= MAX_GRAPH_NUM_SAMPLES)
fill_graphs_point(0, end, 1);
else
{
fract_value = ((double)num_saples_selected) / ((double)MAX_GRAPH_NUM_SAMPLES);
int_value = (int)fract_value;
if (fract_value > int_value)
int_value++;
fill_graphs_point(0, end, int_value);
}
}
void fill_graphs_point(int start, int end, int step)
{
int i = 0;
for (i = start; i < end; i=i+step)
{
dlChart.Series[SERIES_VOLTAGE].Points.AddXY(timestamps_array[i], voltage_array[i]);
dlChart.Series[SERIES_CURRENT].Points.AddXY(timestamps_array[i], current_array[i]);
dlChart.Series[SERIES_ENERGY].Points.AddXY(timestamps_array[i], energy_array[i]);
// I will use this to came back to real position of the initial array
decimation_positions.Add(i);
}
}
void draw\u图形(int开始,int结束)
{
双分形_值=0;
int_值=0;
int num_saples_selected=结束-开始;
if(选定的内部值)
int_值++;
填充点(0,结束,int值);
}
}
空填充图点(整数开始、整数结束、整数步)
{
int i=0;
用于(i=开始;i<结束;i=i+步进)
{
dlChart.Series[Series_VOLTAGE].Points.AddXY(时间戳_数组[i],电压_数组[i]);
dlChart.Series[Series_CURRENT].Points.AddXY(时间戳_数组[i],当前_数组[i]);
dlChart.Series[Series_ENERGY].Points.AddXY(timestamps_array[i],ENERGY_array[i]);
//我将使用它返回初始数组的实际位置
抽取位置。添加(i);
}
}
假设我有一个减少点数的好主意,我不知道在哪里调用函数“draw_graph”。如果我把它放在AxisViewChanged方法中,当我滚动(水平)图形时,它也会调用我的方法,这不是我想要的。我只想在缩放和取消缩放事件中调用我的方法
预期行为:在第一个视图中(无任何缩放),图形必须显示图形趋势的“想法”。然后,对于每个选择/(取消)缩放,我想调用我的函数来检查所选部分的点数是否适合我的窗口大小,即MAX_GRAPH_NUM_SAMPLES(=10000)
希望有人能帮助我。无论您提出什么样的建议,我们都将不胜感激。提前谢谢。我忘了说,奇怪的是,当我放大不止一次时,问题出现了。在某个时候,PC风扇也启动了。我决定禁用库缩放并实现我自己的一种缩放(稍微简单一点)。解决方法就是这个方法,我在问题中写的方法是:
private void dlChart_SelectionRangeChange(object sender, CursorEventArgs e)
{
double startSelection = e.NewSelectionStart;
double endSelection = e.NewSelectionEnd;
// Allow the selection to disappear
reset_selection();
try
{
// before convert point from "showed point" to "real point" I check the limits
if (
(startSelection >= 0) && (startSelection <= decimation_positions.Count()) &&
(endSelection >= 0) && (endSelection <= decimation_positions.Count()) &&
(endSelection != startSelection)
)
{
// convert
startSelection = decimation_positions[(int)startSelection];
endSelection = decimation_positions[(int)endSelection];
// check for reverse zoom (from right to left)
if (startSelection > endSelection)
{
double tmp = startSelection;
startSelection = endSelection;
endSelection = tmp;
}
// clean the series
this.reset_series();
// draw the selected range
draw_graph((int)startSelection, (int)endSelection);
}
}catch(ArgumentOutOfRangeException ex)
{
// todo
}
//System.Console.WriteLine("SelSTART = "+e.NewSelectionStart+" SelEND = "+e.NewSelectionEnd);
}
private void dlChart\u SelectionRangeChange(对象发送方、游标或目标方)
{
double startSelection=e.NewsSelectionStart;
双端选择=e.NewSelectionEnd;
//允许选择消失
重置_选择();
尝试
{
//在将点从“显示点”转换为“真实点”之前,我检查限制
如果(
(startSelection>=0)和&(startSelection=0)和&(endSelection-endSelection)
{
双tmp=开始选择;
开始选择=结束选择;
endSelection=tmp;
}
//清洁系列
这个.reset_series();
//绘制所选范围
绘制图形((int)开始选择,(int)结束选择);
}
}捕获(ArgumentOutOfRangeException ex)
{
//待办事项
}
//System.Console.WriteLine(“SelSTART=“+e.NewSelectionStart+”SelEND=“+e.NewSelectionEnd”);
}
从来没有一个很好的理由将这么多的点转储到图表中,没有人有那么大的监视器。只要在创建系列之前过滤数据就行了。谢谢你,汉斯,这样我尝试过滤点以减少它们的数量。也许我不是很清楚:在第一个视图中(没有任何缩放),grpah必须显示一个“想法”然后,对于每次选择/(取消)缩放,我想调用我的函数来检查所选部分的点数是否适合我的窗口大小,即(MAX\u graph\u NUM\u SAMPLES=10000)有一个AxisViewChanged
,我将使用它来确定我们是否需要通过将点集合更改为其他数据集来准备放大或缩小。但是还有其他UI解决方案,它们不太难编码。请参阅一个用户会接受的示例。..the(德语)标签从1天到5年,最长..在任何情况下我都解决了