c# - 创建Horiz。数据在屏幕上绘制时图表上的滚动条 [英] c# - create Horiz. scrollbar on chart when data is plotted off-screen

查看:134
本文介绍了c# - 创建Horiz。数据在屏幕上绘制时图表上的滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个折线图,在绘制了足够的数据点之后,数据将超过屏幕上显示的数据(以便图表只显示最近的数据)。当这种情况发生时,我想为X轴填充一个滚动条,允许用户使用滚动条查看以前的数据。

I have a line chart, which, after enough data points have been plotted to it, the data will exceed what is visible on screen (so that the chart is only showing the most recent data). When this occurs, I would like a scroll bar to be filled for the X axis, allowing the user to use the scroll bar to view such previous data.

我如何去做这个?我不希望用户能够拖动或缩放图表本身,只需使用滚动条在图表中导航。

How do I go about doing this? I don't want the user to be able to drag or zoom on the chart itself, just to solely use the scroll bar to navigate along the chart.

查看本文: https://msdn.microsoft.com/en-us/ library / dd456730.aspx 但它不帮助&滚动条不会出现。

I've looked at this article: https://msdn.microsoft.com/en-us/library/dd456730.aspx but it doesn't help & the scrollbars do not appear.

推荐答案

没有看到代码的相关部分,很难确定你的问题。

Without seeing the relevant parts of your code it is hard to pin down your problems.

这是一个奇怪的语句:


在绘制了足够的数据点后,数据将超过
在屏幕上显示的内容(所以图表只显示最近的数据)。

after enough data points have been plotted to it, the data will exceed what is visible on screen (so that the chart is only showing the most recent data).

在您设置 AxisX.Maximum 之后,因为默认情况下,图表控件会在添加点时挤压该区域。

Now this can only happen after you have set the AxisX.Maximum because by default the chart control will squeeze the area more and more while you add points.

但是当你设置了可以显示的最大值时,没有滚动条可以工作,甚至被显示。听起来很合理,对吧?

But when you have set a maximum of what can be shown, no scrollbar can work or even been shown. Sounds logical, right?

所以,不要将它设置在第一位置,或当点数超过你想要显示的点数时清除它。要清除它,请使用 NaN

So either don't set it in the first place or clear it when the number of points exceeds what you want to show. To clear it use NaN :

chart1.ChartAreas[0].AxisX.Maximum = Double.NaN;

或者,将其设置为您要显示的最后一个点!

Or, of course, set it to the last point you want to be shown!

查看你不能做的事情后,看看你需要做什么来显示滚动条:

After looking at what you mustn't do let's see what you need to do to show the scrollbar:

首先启用它:

chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;

接下来你要让它只显示滚动手柄而不是缩放重置按钮:

Next you tell it to show only the scrolling handle and not the zoom-reset button:

chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;

请参阅 MSDN on ScrollBarButtonStyles for

See MSDN on ScrollBarButtonStyles for the various things the scrollbar can show/do!

并确保用户无法通过缩放设置:

And to make sure the user can't zoom set this:

chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = false;

最后设置当前范围以显示:

And finally set the current range to show:

chart1.ChartAreas [0] .AxisX.ScaleView.Size = 111; //显示111 DataPoints

chart1.ChartAreas[0].AxisX.ScaleView.Size = 111; // show 111 DataPoints

现在滚动条应该显示。

这是一个好主意, a href =https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.axisscaleview%28v=vs.110%29.aspx =nofollow> AxisScaleView class ,因为它有一些有用的属性..

It is a good idea to study the AxisScaleView class as it has a couple of helpful properties..

根据你的X的数据类型 - 您可能还需要将 ScaleView.MinSizeType 设置为适合您的数据的任何值:

Depending on the data type of your X-Values you may also need to set the ScaleView.MinSizeType to whatever suits your data:

chart1.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Number; 

这篇关于c# - 创建Horiz。数据在屏幕上绘制时图表上的滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆