Support of several X-coordinates for same Y-coordinate · Issue #1629 · oxyplot/oxyplot · GitHub
Skip to content

Support of several X-coordinates for same Y-coordinate #1629

Closed

Description

@abrasat

Feature description

I have an application where each line-series contains points that are looking like this: (Xn_1, Xn_2, Yn).
Practically for each Y value there are 2 corresponding X-values: one of them is for instance some absolute X-value (could be a DateTime time-stamp) and the second X value is for instance a relatively calculated value (like a percentage from something). I would then add 2 linear axes to the plot, one for the each of the 2 defined X values.
Could the DataPoint class be extended to take several X coordinates for one Y coordinate?

Activity

  1. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    Realistically, I think not. There have been a couple of other issues lately discussing having multiple sets of labels per axis (#1357, #1336), and perhaps this would be worth thinking about.

    To some extent, these could addressed by having multiple axes on different tiers all slaved together.

    What is your end goal in terms of user experience?

  2. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    For the application I am thinking about, I have actually a plot with line-series representing the values of different process data between 2 events (like start and end of production process). The 2 events represent the 0 - 100 % scale which is used for the X axis.
    I would need the option to add a second X axis to represent the absolute time-stamps for the data points between the 2 events (an option would be to toggle between the 2 X axes, or, maybe even better, to be able to add/remove the DateTime X axis whenever the user activates it, by context menu or whatever)..
    Right now I show the DateTime values for each DataPoint in a customized TrackerFormatString, but having an optional additional DateTime axis would be much more user-friendly)

  3. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    Is there any possiblity to stack two X axes at the bottom, one above the other?

    I tried this, but the X axes override each other:

    myPlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "First X-Axis" });
    myPlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Second X-Axis"});
    
  4. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    Yes, the Axis.PositionTier property allows you to stack axes on the same size of the plot (there is big example in example library under Axis Examples).

  5. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    Ok, thanks, I will take a look.
    Is it possible to run the examples from the example library ?
    Later edit: Found it, the ExampleBrowser.WPF

  6. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    Unfortunately I dont see the second axis as in the example browser. The scale of the second linear axis is dsplayed, but the values below the scale and the title are missing. Looks that these are cut off from the plot view. I tried to set the Margin property of the PlotView, but it did not help. Any idea what happens?

  7. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    That does sound like an issue with the margins: can you provide a screen shot or reproducing code?

    If you set the margins to NaN, do they appear? Axes exist within the plot the margins, so if they are set manually, then they need to accommodate all the axes.

    It's also possible that no tick marks have been computed for it for some reason (e.g. if the interval/step is large and the axis is small).

  8. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    Actual code + screenshot.
    Is it necessary to calculate minimum and maximum for the second axis? But why is not even the title displayed?

    position_tier_x_axes

    myPlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, PositionTier = 0, Title = "Processing (%)" });
    myPlotModel.Axes.Add(new LinearAxis { 
                        AxislineStyle = LineStyle.Solid,
                        Position = AxisPosition.Bottom,
                        PositionTier = 1,
                        Title = "Time"
                    });
    
  9. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    It will be necessary to compute them if you want it to say anything meaningful, but it should default to [0, 100] and display as such.

    It does look exactly like it is being clipped. If you make the plot margin NaN or double whatever it is now, does that change anything at all?

  10. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    I had this margin in xaml:

    <Grid>
        <oxySkia:PlotView Model="{Binding Model.PlotModel}" Controller="{Binding Model.PlotController,UpdateSourceTrigger=PropertyChanged}" Background="White" Margin="30,30,30,30">
    
    

    How can I set NaN as Margin?

    The second axis should actually be a DateTime axis, and I could compute the minimum and maximum values. I guess that it is not obligatory that the second X axis is also a LinearAxis.
    But as a first step I was trying to display a second X axis at all. Of course actually there is no correlation at all between the second axis and any DataPoints, there are no dataPoints assigned to it. All the DataPoints are assigned to the first X axis. That was the reason of my initial question, if it is possible to store two different X values in the same DataPoint.

  11. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    The margin on the PlotView is just the margin defined for any control. You have to set it on PlotModel, where it should default to all NaN. Could the PlotModel.Margin be being set elsewhere? This is often done to avoid the axes 'bouncing' because OxyPlot computes them based on what is displayed, and this can be undesirable upon user interaction.

  12. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    You are right, thanks!
    I had this:

    var myPlotModel = new PlotModel
                    {
                        Title = plotTitle,
                        PlotMargins = new OxyThickness(50, 0, 0, 40)
                    };
    

    After changing to this

    var myPlotModel = new PlotModel
                    {
                        Title = plotTitle,
                        PlotMargins = new OxyThickness(50, 0, 0, 80)
                    };
    

    , I see the second X axis

  13. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    Is there any possibility to couple/synchronize the second DateTime X axis with the first X axis? For instance when zooming the plot and respectively the first X-axis, to also zoom/adapt the DateTime X axis. Does anyone have maybe a code sample about how to achieve such a functionality?

  14. VisualMelon commented on Jul 22, 2020

    @VisualMelon
    Contributor

    There is no built in support for slaving. It's been a while since I tried, but you should be able to hook on OnAxisChanged on both axes and update the other accordingly. This should work because it isn't called when you change the minimum/maximum directly, but it means that any manual update will have to be intercepted some other way.

    The example library could do with an example of this...

  15. abrasat commented on Jul 22, 2020

    @abrasat
    Author

    I understand the theory, not sure about the practical implementation...
    To get the "Zoom effect" on the second axis I would have to calculate somehow the "zoom factor" on the first X-Axis in OnAxisChanged?
    And then to zoom manually the second X axis, I would have to recalculate the minimum and maximum properties for it?
    Unfortunately there are no samples of handling OnAxisChanged or calling ZoomAt in the example library...

  16. 10 remaining items

  17. abrasat commented on Jul 23, 2020

    @abrasat
    Author

    Ok, I understand now. How could I display for instance something like "15.03.2014" instead of the day of the week?

    And one more question about the helper functions DateTimeAxis.ToDouble(DateTime value) and DateTimeAxis.ToDateTimeValue(double value). If I write this code:

    var dtNow = DateTime.Now;
    var dtDouble = DateTimeAxis.ToDouble(dtNow);
    var dtNowAgain = DateTimeAxis.ToDateTime(dtDouble);
    

    , the dtNow variable has the Kind property set to DateTime.Local, but dtNowAgain has the Kind property set to DateTime.Utc (the other values are identical).
    Could be eventually a bug.

  18. VisualMelon commented on Jul 23, 2020

    @VisualMelon
    Contributor

    Check out String Formatting.

    Regarding datetime local/UTC, the static methods have to pick one and run with it, so there isn't much that can be done there. This could be a problem for presentation, but that can always be overriden.

  19. abrasat commented on Jul 23, 2020

    @abrasat
    Author

    Ok, I will check it.
    I think the Kind property is read-only, can be set only when constructing a DateTime.

  20. VisualMelon commented on Jul 23, 2020

    @VisualMelon
    Contributor

    The default legends only render series. You could override and extend them to do otherwise, but it would be a lot of work.

    In terms of long-term improvements, an ILegendItem interface might be a good idea: there isn't always a one-one mapping between series and legend entries, and it could allow other things (e.g. annotations) to join in. If you have ideas that would influence such a design, do make an issue about them so we can keep track of them.

  21. VisualMelon commented on Jul 23, 2020

    @VisualMelon
    Contributor

    The issue with the date disappearing presumably coincides with a tick appearing: at the point it stops rendering just one label and tries to render many, but they are probably 'off-screen'. It might make sense to detect if there is only one and re-center it.

  22. abrasat commented on Jul 23, 2020

    @abrasat
    Author

    Ok, thanks.
    P.S. Not sure what happened, my last posting disappeared.

  23. abrasat commented on Jul 24, 2020

    @abrasat
    Author

    Is there any setting that allows displaying the title of a X Axis directly on the right (or left) side of the axis line, instead of below it?
    Can the font size of the label texts for the axis be configured?

  24. VisualMelon commented on Jul 24, 2020

    @VisualMelon
    Contributor

    Title position isn't configurable (it's an old issue (#22) with a lot of difficulties with regards to how different axes with offset-titles should interact which the layout system can't really handle at the moment).

    Label size should be controlled by by PlotElement.FontSize.

  25. abrasat commented on Jul 24, 2020

    @abrasat
    Author

    The configuration of the title position would be a very useful feature in my opinion...
    What about the font size of the axis title, can this also be configured?

  26. VisualMelon commented on Jul 24, 2020

    @VisualMelon
    Contributor

    What it needs is someone familiar with the library to invest in the design work. It could probably be done quite easily, but it would go wrong when you have lots of axes. Maybe I'll have a go at a prototype over the weekend...

    Axis title is Axis.TitleFontSize, though I think there is a bug in 2.0 involving that.

  27. abrasat commented on Jul 24, 2020

    @abrasat
    Author

    Thanks, it seems to work for my application

  28. abrasat commented on Aug 10, 2020

    @abrasat
    Author

    @VisualMelon : Should be possible to zoom the X-axis in my scenario? By moving the mouse wheel only the y-axis is zoomed. Where exactly should I place the mouse cursor (as decribed here to get the zoom for the x axis working?
    The same question for pan (works also only for the y axis).

  29. VisualMelon commented on Aug 10, 2020

    @VisualMelon
    Contributor

    @abrasat Without looking at your code for the plot model and controller, I can't really help. An X axis should always zoom when the mouse is over the plot area. Check you don't have any invisible axes, or axes which are configurated as non-zoomable/pannable or have absolute bounds.

  30. abrasat commented on Aug 10, 2020

    @abrasat
    Author

    @VisualMelon I used basically the code above in this issue, to synchronize the additional x-axes with the x axis that I initially had (the one with the percentage values).
    The problem seems to be in this code, with the 2-way synchronization of the x-axes.

    Slave(y2axis, yaxis, x => x * 100);
    Slave(yaxis, y2axis, x => x / 100);
    

    If I remove the second Slave() call and thus have only a "one-way" axis synchronization, the zoom and pan functions work normally, also with the additional x axes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions