简体   繁体   English

Oxyplot-在LineSeries中编辑左键单击标签

[英]Oxyplot - edit the left-click label in a LineSeries

I'm plotting a few different LineSeries in Oxyplot (in C#, using Windows Forms), which all have wildly different ranges. 我正在Oxyplot中绘制一些不同的LineSeries(在C#中,使用Windows窗体),它们的范围都有很大不同。 To make every series still visible, I'm scaling all their values to the range from 0 to 1. Of course the problem here is, that the actual values of the series can't be displayed anymore, so I wondered if it's possible to change the left-click event that displays the X and Y value of a DataPoint to fix this. 为了使每个系列仍然可见,我将所有值缩放到从0到1的范围。当然,这里的问题是,该系列的实际值不再显示了,所以我想知道是否有可能更改显示DataPoint的X和Y值的左键单击事件以解决此问题。 If possible, I'd like it so that when the user clicks on a datapoint, the displayed Y-value would be scaled back to the original, while the graph remains scaled down. 如果可能的话,我希望这样做,以便当用户单击数据点时,显示的Y值将被缩放回原始值,而图形仍保持按比例缩小。

For example, I have a Na+ value ranging from 130 to 150, which I then scale to 0 and 1. But when the user clicks on a Datapoint, I want it to display Y = 140 and not 0.5. 例如,我有一个Na +值,范围从130到150,然后将其缩放到0和1。但是当用户单击一个数据点时,我希望它显示Y = 140而不是0.5。 Since every LineSeries has a different scaling factor, this would also mean that I'd have to edit the label for each series seperately. 由于每个LineSeries都有不同的缩放比例,因此这也意味着我必须分别编辑每个系列的标签。

So yeah, is something like that possible in the current version? 是的,在当前版本中可能会发生这种情况吗? Thanks in advance! 提前致谢!

Edit: I figured it out, see my answer below! 编辑:我想通了,请参阅下面的答案!

I'm not sure if I'm supposed to answer my own question, but I ended up figuring it out. 我不确定是否应该回答自己的问题,但最终还是弄清楚了。 So anyway, it turns out I can't access any of the properties needed, so I just made my own class for the Datapoints and included a property for the scaled value. 因此,无论如何,事实证明我无法访问所需的任何属性,因此我只是为数据点创建了自己的类,并为缩放值添加了一个属性。 It turns out that the Tracker is capable of displaying other properties of the Datapoints, but the standard Datapoints only has X and Y. Then I modified the TrackerFormatString to show the scaled value instead of the actual one. 事实证明,跟踪器能够显示数据点的其他属性,但是标准数据点仅具有X和Y。然后,我修改了TrackerFormatString以显示缩放值,而不是实际值。

        public class MeasurePoint : IDataPointProvider
    {
        public MeasurePoint(double x, double y, double scale)
        {
            X = x; Y = y; Scale = scale;
        }

        public double X { get; set; }
        public double Y { get; set; }
        public double Scale { get; set; }
        public DataPoint GetDataPoint()
        {
            return new DataPoint(X, Y);
        }
    }

That is the class I created and this is how I ended up handling the points. 那就是我创建的类,这就是我最终处理这些要点的方式。

            var points = new MeasurePoint[Y.Count - 1];
        for (int i = 0; i < Y.Count; i++)
        {
            points[i] = new MeasurePoint(DateTimeAxis.ToDouble(X[i]), Y[i], Y[i]*scale);
        }
        Series.ItemsSource = points;
        Series.TrackerFormatString = "{0}\n{2}\n{Scale}";

scale here is the factor that I divide the values with before plotting and the TrackerFormatString is {0} the Series name and {2} is the X value. 缩放比例是在绘制之前我将这些值除以的因子,TrackerFormatString是系列名称{0},而{2}是X值。

Works pretty great! 效果很好!

You can't directly change the displayed data, however you can listen to the mousedown event within the oxyplot like this: 您不能直接更改显示的数据,但是可以像这样在oxyplot中监听mousedown事件:

var model= new PlotModel();
model.MouseDown += Model_MouseDown;

private void Model_MouseDown(object sender, OxyMouseDownEventArgs e)
{
    var controller = sender as PlotController;
    var position = e.HitTestResult;
}

With the values of position you can calculate back to the actual value and display it somewhere else. 使用position值,您可以计算回实际值并将其显示在其他位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM