This is the discussion forum for OxyPlot.
For bugs and new features, use the issue tracker located at GitHub.
Also try the chat room!

DateTime Label Formatter over 2 lines

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

SteveReedSr wrote at 2014-07-07 05:29:

My client wants the date time formatted on the Labels to be formatted with the date above the time, like this:

07/06
10:00 am

I have been unable to determine how to a) get it broken onto 2 lines (I've tried putting \n in the format string without success), and b) how to get the am / pm designator.

I'm doing this using Xamarin for Android

Thanks in advance!

objo wrote at 2014-07-10 12:21:

I don't think multiline strings is supported, so this must be implemented on the DateTimeAxis.
I have added https://oxyplot.codeplex.com/workitem/10228

Performance improvement with DateTimeAxis

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

kidproquo wrote at 2012-08-17 14:36:

Hi,

In your wiki page for performance, you mention that the slowest performance is when we set ItemsSource and use the data field properties.

However, this is what is done in the DateTimeDemo (Examples.WPF.WpfExample.DateTimeDemo). I followed this tutorial to have 300k points with DateTimeAxis in the bottom and a LinearAxis on the left. The chart is slow to respond to mouse events (click/zoom/resize window, etc.).

Any way to optimize this? How can I use IDataPoint or Mapping (the first three recommendations in the performance page) when my X-axis data is of type DateTime?

Regards,

Kid


kidproquo wrote at 2012-08-18 03:07:

Ah..I figured it out. Now I do this:

mySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(myDateTime),myValue))

However, plot response is slow for 300k points. Any suggestions?

 


objo wrote at 2012-08-21 13:18:

If you use a ScatterSeries, you can increase the "BinSize" property - but this will make a less accurate plot... 

You should also run a performance profiler to see if the bottleneck is in your code, oxyplot or wpf.

Small typo in OxyPlot.Metro.csproj XML

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

dcuccia wrote at 2012-06-24 02:32:

First, off - awesome library. Second, I checked out Thursday's changeset (bdba153d17f0) and attempted to load the Metro solution/project - ran into this message. Looks like the runtime reference in the XML has a typo - changed the following framework reference from v1.0 to v11.0 as follows and it worked:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v11.0\Microsoft.Windows.UI.Xaml.CSharp.targets" />


objo wrote at 2012-06-26 06:06:

Thanks! I changed the version numbers.

Note that this was done with the first preview of VS2012/Metro, I have not tested with the latest release candidate yet.

Feel free to create a fork if you do more work to get the Metro version running!

PNG encoder changes?

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

thomasdr wrote at 2013-12-16 19:25:

Can you explain the recent PNG encoder changes? My image is now rotated 90 degrees clockwise from previous.

objo wrote at 2013-12-16 20:55:

I think this is related to the breaking change applied 2013-11-14:
https://oxyplot.codeplex.com/SourceControl/changeset/62c4f57c6da9
(to make all the pixel arrays consistent - in OxyImage, pdf exporter, png encoder etc)

See the documentation for the PngEncoder.Export method, I guess you need to change the order of the indices in the source array:
        /// <summary>
        /// Encodes the specified image data to png.
        /// </summary>
        /// <param name="pixels">
        /// The pixel data indexed as [x,y] (bottom line first).
        /// </param>
        /// <returns>
        /// The png image data.
        /// </returns>
        public byte[] Encode(OxyColor[,] pixels)
Let me know if it would be a better idea that pixel arrays are indexed as [y,x] or top line first!

thomasdr wrote at 2013-12-30 15:45:

OK, I switched the indexes and everything works fine. Hope you received the PDF book from your Amazon wish list. Thanks again for this library.

objo wrote at 2014-01-07 21:36:

Thank you! I received the book yesterday! I am looking really forward to read it, I find PDF export to be very exciting :) (and I want to learn more about text encoding and font embedding)

How can I make line series color, axis label color & axis title color to be the same.

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

krishnaramuu wrote at 2014-04-19 12:01:

I am using winforms oxyplot and How can I make line series color, axis label color & axis title color to be the same.
Thanks,
Ramakrishna

objo wrote at 2014-04-25 09:40:

See new example (the last one under Z0 Discussions in the example browser).
For the axis use the TitleColor and TextColor properties, for the LineSeries use the Color property.

BarSeries axis

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

jezza323 wrote at 2012-01-05 17:02:

Looking at the Histogram example, is there a way currently to set a MajorStep on the CategoryAxis so that not every number on the axis is displayed, say every 5th one as you would get if it were a regular LinearAxis? If not is anyone else interested in this functionality?


jezza323 wrote at 2012-01-05 21:17:

Playing with the code I am able to make a change so the default behaviour stays as is, but Majorsteps are supported. I will submit a patch if anyone else has interest?


objo wrote at 2012-01-05 21:26:

Yes, it sounds ok to use MajorStep to provide this functionality. Please submit a patch :)


jezza323 wrote at 2012-01-06 19:15:

Patch submitted, please see WorkItem 9787

OxyPlot paint Exception : XAxis not defined

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

OverDriver wrote at 2014-07-14 17:51:

Thanks for Oxyplot!
I had this bug (OxyPlot paint Exception : XAxis not defined ) in my code. If I scale the plot with mouse it goes away but I can always see it when something is newly plotted. I did add axes to my Model.

Here's the code
newPlot.DrawGraph(graphMain);// this calls DrawGraph function

public void DrawGraph(OxyPlot.WindowsForms.PlotView iptGraph)
        {
            var tmp=new OxyPlot.Series.LineSeries();
            tmp.StrokeThickness= 0.4;
            for (int i = 0; i < _resampledPoints.Count(); i++)
            {
                tmp.Points.Add(_resampledPoints[i]);
            }
            iptGraph.Model.Series.Add(tmp);
        }
Thanks a lot!

Slxe wrote at 2014-07-14 19:08:

So just a few things, first of all you can use a foreach loop or even just AddRange over what you're currently doing (and it's less bug prone):
foreach (var p in _resampledPoints)
    tmp.Points.Add(p);
Alternatively:
tmp.Points.AddRange(_resampledPoints);
Both require _resampledPoints to be an IEnumerable<DataPoint> collection.

Second, please provide the code you use to assign the horizontal axis (or just all of them) to the PlotModel, can't really help when you're just adding points to a series =P.

OverDriver wrote at 2014-07-14 19:27:

Thank you for your suggestion! I'm pretty new to C# :)
These are the codes that I use to add axies to the PlotModel (graphMain).
        OxyPlot.Axes.LinearAxis XAxis = new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinimumPadding = 10, MaximumPadding = 15, AbsoluteMinimum = 0,Maximum=80};
        OxyPlot.Axes.LinearAxis YAxis = new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinimumPadding = 10, MaximumPadding = 15, AbsoluteMinimum = 0, Maximum=400};
            graphMain.Model.Axes.Add(YAxis);
            graphMain.Model.Axes.Add(XAxis);
If I try to define plotmodel under DrawGraph function this exception actually disappears. But I need to add multiple lines to PlotModel so I can't really do that.

Slxe wrote at 2014-07-14 20:11:

Just out of curiosity, why are you setting a min and max for the axes? They will actually automatically resize based on the points in the series collection, so unless you want to see a certain range it's better to leave them to do the work instead. I'd suggest setting their min and max until after you add data to the series (same with the padding, it'll calculate that stuff itself). Also, it's probably best to use an axis Key, and a YAxisKey on the series. Just as a quick example:
using System.Linq;

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

// cut out namespace and class definitions to save indention levels
private void InitializeChart() 
{
    // didn't see it in your code, but you should initialize your own PlotModel and assign it to the
    // PlotView before using PlotView.Model
    var model = new PlotModel();

    model.Axes.Add(new LinearAxis
    {
        Key = "xAxis",
        Position = AxisPosition.Bottom,
        Title = "X Axis"
    });

    // just to show another way of using the new axis
    var yAxis = new LinearAxis 
    {
        Key = "yAxis",
        Position = AxisPosition.Left,
        Title = "Y Axis"
    };

    // the series title will show up in the legend
    var series = new LineSeries {Title = "Resampled Points", YAxisKey = "yAxis"};
    foreach (var p in _resampledPoints)
        series.Points.Add(p);

    // two examples of how to get the axes, highly suggest LINQ if you're in dotNet 3.0+
    model.Axes.OfType<LinearAxis>().First(a => a.Key == "xAxis").AbsoluteMinimum = 0;
    model.Axes.OfType<LinearAxis>().First(a => a.Key == "xAxis").Maximum = 80;

    yAxis.AbsoluteMinimum = 0;
    yAxis.Maximum = 400;

    // I'm guessing your graphMain is your PlotView
    graphMain.Model = model;
}
Note: this might have some errors, just put it together quickly in Sublime Text from memory.

Not really sure what you mean by defining it under the drawgraph function, you'll have to elaborate.

Also, welcome to C#! I've been in this space for around 5 months now, came from Python and Java myself, mainly for work. Quite enjoying the language (don't really like the framework restrictions though, being a linux guy), hope you like it here! I'm currently playing around with F# myself, really falling for functional programming lately.

OverDriver wrote at 2014-07-14 20:30:

Thanks for your response. I did initialized model. But my problem is, I am passing PlotView to another function to add a line series. Then the exception comes. If I put add line series at where i define the Model, the bug disappears. I don't understand why.

Thanks!
public void DrawGraph(OxyPlot.WindowsForms.PlotView iptGraph)//this function will add line series to PlotView
        {
            var tmpModel = new OxyPlot.PlotModel();
            int xpixels = iptGraph.Width;
            double xratio = (double)_points.Count() / (double)xpixels;
            var tmp = new OxyPlot.Series.LineSeries();
            _resampledPoints.Clear();
            for (int i = 0; i < xpixels; i++)//set resampled points
            {
                int idx = (int)(i * xratio);
                _resampledPoints.Add(new OxyPlot.DataPoint(_points[idx].X+_xOffset, _points[idx].Y+_yOffset));
                if (_xMax < _points[idx].X) _xMax = _points[idx].X;
                if (_yMax < _points[idx].Y) _yMax = _points[idx].Y;
            }
            tmp.StrokeThickness= 0.4;
            tmp.Points.AddRange(_resampledPoints);
            iptGraph.Model.Series.Add(tmp); //Here I add tmp line to PlotView graph
        }


Slxe wrote at 2014-07-14 20:54:

Tip: put a space and "C#" after the triple back tick for code highlighting =). DrawGraph sounds a bit misleading, since you're just adding data to the graph, not actually effecting how it will draw itself. I'd consider moving the functionality of adding points to series into the class that handles the PlotView directly over passing the PlotView around like that (or at least pass the PlotModel instead, don't need the view).

For example in your chart class you can have an InitializeChart() method that sets up basic axes and series, (or for more dynamic control, InitializeChart(), AddSeries(various series info arguments), and AddAxis(various axes info arguments), and some kind of AddPoints(object tag, IEnumerable<DataPoints>) to add data to the series, using the tag to look up the correct one with linq (view.Model.Series.First(s => s.Tag == tag), or Single if you're only expecting one result).

I'm actually doing something similar to this in a simplified custom control I'm making for work, if you need a more comprehensive example I'd be happy to share.

OverDriver wrote at 2014-07-14 21:13:

Thanks for your suggestion! I finally fixed the bug. What I did is every time I plot the data set, I create a new model and add all the lines to the model. Then I assign it to PlotView. I'm guessing I should not add line separately? This will require extra work because each time a new line is added, I need to plot old ones together. But I guess it's just linear time so I'll leave it like that.
I'll try the Linq! It looks very handy.

Thanks again!

Slxe wrote at 2014-07-14 21:19:

Hmm that's a good point, kind of annoyed I missed that lol, yea you're remaking and assigning the PlotModel everytime that function is called. It'd probably be better to add the series and points separately, that way you can separate adding a new line series and adding data to an already existing line series on the plot. Also, if you don't already know, you need to make the PlotView refresh manually, calling Model.InvalidatePlot(bool), boolean being true/false depending on if you want the axes to recalculate and resize themselves based on new data in the line series (this is actually called every time you pan or zoom automatically).

OverDriver wrote at 2014-07-14 22:05:

It's great to know the InvalidatePlot thing! I was required to add zoom functionality to zoom specific part according to user input.

More than one legend

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

jesusvpct wrote at 2014-06-02 12:11:

Is there any way to have more than one legend like in mschart? I need to group in two blocks different series, because they have different title (meaning) but they must be represented together.

Thanks.

objo wrote at 2014-06-06 21:01:

I don't think this is currently possible.
We have a similar feature request in https://oxyplot.codeplex.com/workitem/9192

How is this defined in mschart?
Could we add a LegendGroup property to the series? Then define how the legend groups should be presented in the plot model.
0
Under review

Margin for the ResetAllAxis command and take into account annotations

Xavier Hahn 10 years ago updated by anonymous 10 years ago 3
I'm using heavily the "reset all axis" functionality in my application, but I don't like the fact that the axes are set exactly at the minimum and maximum points. I would like to be able to add a small margin (in pixels maybe?) so that the points are not completely on the end of the axes.

Also, I would like to have a way to force annotation to be took into consideration for the reset axis. I use some annotations to display information and I would like that the annotation is displayed completely when the user reset all the axis.

Maybe something already exists, but I didn't find it.

Thanks

XAML support for ColumnSeries and RectangleBarSeries?

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

RickNZ wrote at 2012-08-29 09:32:

It looks like XAML support isn't yet available for a few types of series, including ColumnSeries and RectangleBarSeries.

Is this a known bug/limitation?


objo wrote at 2012-08-29 10:34:

Yes, all series are not supporting XAML yet. Vote on http://oxyplot.codeplex.com/workitem/9999