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

multiple series

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

putra_wlh wrote at 2012-08-07 12:52:

Hi Objo,
I want to create a graph like in the image .

Image

When i see OxyPlot, thought this can help me to create the graph. Unfortunately, i don't know where i must to begin.
Need advice to create the graph. 

Thank You,


objo wrote at 2012-08-09 00:23:

this looks like annotations - try to add PolygonAnnotation, ArrowAnnotation, TextAnnotation and LineAnnotation to the Annotations collection in the plot model.

And the Blue/orange lines are series? Add LineSeries to the Series collection.

See the examples in the 'Example browser'.


putra_wlh wrote at 2012-08-09 05:12:

thank you for quick respon .

i was try to create using PolygonAnnotation . but i have problem with PolygonAnnotation.Points ..

Actualy i try to convert C# Script to PowerBuilder.Net 12.5 script but i am stuck at PolygonAnnotation.Points , i can't find add function .

There's other way to add value into PolygonAnnotation.Points , or how to create PolygonAnnotation by wpf xaml like LineAnnotation in example .


objo wrote at 2012-08-09 08:50:

Right, I should probably change the PolygonAnnotation.Points from IEnumerable to IList. Now you have to create a new collection, then assign the Points property to the collection.


putra_wlh wrote at 2012-08-09 11:31:

thank you for your response .

I will try to create a new collection. But i don't know it will worked or not .

Hopefully i can use a new update from oxyplot for this issue .

 

best regards,

putra novan


objo wrote at 2012-08-10 12:37:

The type of the property has now been changed.

Reporting (docx writer) and Styles

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

AleV wrote at 2012-10-16 18:59:

I'm happily using the reporting module and I find very useful.

I'd like to be able to specify a default style for the whole table (for the docx export) and not for the text inside the table.  Is it possible?

Also, is there a way to put some content (other than text of course) inside a cell of a table? My intent is to keep multiple charts aligned in my docx document.


objo wrote at 2012-10-16 23:55:

Great to hear that you find the simple reporting classes useful! 

Do you need to set spacing/indentation? Or other table properties? It should be possible to add such a style for the table elements, and I think this could be supported by all the output formats (html, pdf, xps, docx)

Note that this reporting model was designed to be *very* simple, so currently the table cells can only contain text. I will refactor to a more flexible model later (I would also like to have more control of the inline content of the paragraphs).

Check out the OpenXML SDK if you need full control of your docx output. http://www.microsoft.com/en-us/download/details.aspx?id=5124


AleV wrote at 2012-10-17 15:18:

Thanks objo, as far as I understand of your object model, a OxyPlot.Reporting.ReportStyle only specifies the font family of the text, the text of the table or the text of the table headers and they are all "Paragraph Styles".

As you probably know in Word a Style there are different type of styles ("Paragraph", "Character", ..., "Table"): what I'd like to be able to do is to format a table with a table style (for example by applying the Word 2010 built-in "Light Shading - Accent 5 style"), rather than with a paragraph style for the content of the cells. But maybe this is something too specific to docx (or HTML): I have no idea if this also applies to tex, xps or pdf.

Finally, is it possible to put content in the header and footer of the document?

Anyway, thanks a lot for your beautiful software.

 

 

 

 

 


objo wrote at 2012-10-17 15:37:

Yes, the style is only defining paragraph properties. I see some refactoring may be necessary.

I would like to add a feature that creates the document from a Word template file, then I think it should be possible to put all Word-specific styles in there. It should also be possible to add headers and footers (including graphics) in the template file. I have added the feature in http://oxyplot.codeplex.com/workitem/10011

Sorry, I don't have time to implement this right now. But I need it myself in a couple of months from now :)


AleV wrote at 2012-10-17 15:42:

That would be great!

Overlay Curve with Bar Series?

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

alanrorr1 wrote at 2013-10-01 00:51:

Hi,
I just started looking around in case the chart I am using now does not support my needs amply. Wondering, will the OxyPlot chart support a bar series with a smooth curve overlaid. I am looking to show where the bars fall with respect to a fitted curve (i.e. overlaid curve).

Thanks!
Alan

Gimly wrote at 2013-10-01 17:58:

You can use a PolylineAnnotation for this, simply give it the list of fitted points and use Smooth = true.

There's an example in the AnnotationExamples called PolylineAnnotations.

alanrorr1 wrote at 2013-10-02 01:19:

Gimly, Fantastic and thanks! I will give that a try. Best, Alan

alanrorr1 wrote at 2013-10-03 08:37:

Gimly,
Do you happen to have any ideas? I am stuck on this error

Error 2 Argument 1: cannot convert from 'OxyPlot.Wpf.PolylineAnnotation' to 'OxyPlot.Annotations.Annotation' D:\Development\Samples\OxyPlotSample\OxyPlotSample\MainWindow.xaml.cs 83 33 OxyPlotSample

which is caused by this line
        tmp.Annotations.Add(new PolylineAnnotation { Points = new IDataPoint[] { new DataPoint(0, 15), new DataPoint(3, 23), new DataPoint(9, 30), new DataPoint(20, 12), new DataPoint(30, 10) }, Smooth = true, Text = "Smooth Polyline" });
I tried casting the "new PolylineAnnotation" to "OxyPlot.Annotations.Annotation" with no luck.

I am not quite sure what to try next. This is a .Net/WPF application.

Thanks,
Alan

everytimer wrote at 2013-10-03 09:24:

Are you adding the PolylineAnnotation in your code-behind? If so try to refer to your model in the plot:

if plotter is the x:Name of your plot in XAML

in the code behind you need to set something like:
plotter.Model.Annotations.Add(myPoly); 
instead of simply
plotter.Annotations.Add(myPoly);
Good luck

alanrorr1 wrote at 2013-10-03 16:57:

Hi Everytimer,
Thanks for the reply! Yes, PolylineAnnotation is in the code-behind accessing the PlotModel. The XAML refers to the PlotModel through this binding with other properties (i.e. code behind accessing PlotModel) working as expected.
            <oxy:Plot x:Name="MyPlot" Model="{Binding Model1}">
            </oxy:Plot>
I tried your idea of accessing the model directing by naming the plot:
this.MyPlot.Model.Annotations.Add(new PolylineAnnotation { Points = new IDataPoint[] { new DataPoint(0, 15), new DataPoint(3, 23), new DataPoint(9, 30), new DataPoint(20, 12), new DataPoint(30, 10) }, Smooth = true, Text = "Smooth Polyline" });
Unfortunately, I am getting the same compiler error:
Argument 1: cannot convert from 'OxyPlot.Wpf.PolylineAnnotation' to 'OxyPlot.Annotations.Annotation' 
The compiler is seeing Annotations" with the "Add" method, but it looks like it is unable to accept the PolylineAnnotation object in the Add method. The Add method is expecting something it can convert to OxyPlot.Annotations.Annotation. I got this line using PolylineAnnotation from the general examples since I could not find it in the WPF samples.

Thanks!
Alan

everytimer wrote at 2013-10-03 22:18:

Ok, I think you have
using OxyPlot.Wpf;
on top, if so try to add the "normal" PolylineAnnotation:
var myPoly = new OxyPlot.Annotations.PolylineAnnotation() { /* stuff */};
MyPlot.Add(myPoly);
Good luck!

alanrorr1 wrote at 2013-10-04 08:00:

Hi Everytimer,

Beautiful, it compiles - thank you!

Best,
Alan

Add Render event and workaround

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

GeertvanHorrik wrote at 2014-03-26 16:22:

Hi,

Today I was trying to resize the plot to a specific size. The reason is that we need to align the actual plot without axes to a specific size. Unfortunately the sizes cannot be specified (only for the whole control).

I tried to get an event when the plot is being drawn (because I need the PlotArea to have valid values), but there are no events on the PlotModel class.

Below is a workaround which works great:
public static class OxyPlotExtensions
{
    private class RenderAnnotation : Annotation
    {
        public event EventHandler<EventArgs> Rendered;

        public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);

            Rendered.SafeInvoke(this);
        }
    }

    public static void AddRenderHandler(this PlotModel plotModel, EventHandler<EventArgs> handler)
    {
        Argument.IsNotNull(() => plotModel);
        Argument.IsNotNull(() => handler);

        var renderAnnotation = EnsureRenderAnnotation(plotModel);
        renderAnnotation.Rendered += handler;
    }

    public static void RemoveRenderHandler(this PlotModel plotModel, EventHandler<EventArgs> handler)
    {
        Argument.IsNotNull(() => plotModel);
        Argument.IsNotNull(() => handler);

        var renderAnnotation = EnsureRenderAnnotation(plotModel);
        renderAnnotation.Rendered -= handler;
    }

    private static RenderAnnotation EnsureRenderAnnotation(PlotModel plotModel)
    {
        var annotation = plotModel.Annotations.FirstOrDefault(x => x is RenderAnnotation);
        if (annotation == null)
        {
            annotation = new RenderAnnotation();
            plotModel.Annotations.Add(annotation);
        }

        return (RenderAnnotation)annotation;
    }
}
Maybe you can add the Render event to the PlotModel so everyone can do something when the plot is being rendered?

tibel wrote at 2014-03-26 19:20:

Rendering does belong to the control not to the model.

GeertvanHorrik wrote at 2014-03-26 19:42:

I fully agree. But then why is there a PlotArea on the model? And although the render itself is not part of the model, it would be very nice if I could at least be notified when the model is being rendered by the control.

objo wrote at 2014-03-26 20:45:

Did you try setting the Width, Height, AutoAdjustPlotMargins and PlotMargins of the Plot control? If you do this, I think the size of the plot should be fixed.
It is easy to add Rendering/Rendered events to the PlotModel, but I would like to avoid it if it is not really needed.
The PlotModel was meant to be the abstraction of the plot view - so it contains both the "plot area" and all the transforms that are related to the size of the view. See also https://oxyplot.codeplex.com/workitem/10133 which is related to this.

GeertvanHorrik wrote at 2014-03-26 20:51:

What I did was to use the Padding of the PlotModel to make sure that the plotarea itself always has a fixed size. Below is the code that allows a developer to make the width of the PlotArea (thus the plot itself can be larger) exactly the size of RealPlotWidth.
private void UpdatePlotArea(int dispatchCounter = 0)
{
    if (!plot.IsVisible)
    {
        return;
    }

    var plotWidth = plot.ActualWidth;
    if (plotWidth == 0d)
    {
        return;
    }

    var plotModel = plot.Model;
    if (plotModel == null)
    {
        return;
    }

    if (plotModel.PlotArea.Width == 0d)
    {
        if (dispatchCounter < 5)
        {
            Dispatcher.BeginInvoke(() => UpdatePlotArea(dispatchCounter + 1));
        }
        return;
    }

    // Magic constants we need to fix the left and right margins of Oxyplot
    const int RightPadding = 5;
    const int DefaultOxyplotPadding = 8;

    var axisWidth = plotModel.PlotArea.Left - plotModel.PlotAndAxisArea.Left + DefaultOxyplotPadding;

    var leftPadding = plot.ActualWidth - RealPlotWidth - axisWidth - DefaultOxyplotPadding;
    if (leftPadding < 50)
    {
        // Exit, issue with redrawing
        return;
    }

    var padding = new OxyThickness(leftPadding, 0, RightPadding + DefaultOxyplotPadding, 0);
    if (AreEqualOxyThickness(padding, plotModel.Padding))
    {
        return;
    }

    plotModel.Padding = padding;
    plotModel.InvalidatePlot(false);
}

private static bool AreEqualOxyThickness(OxyThickness oxyThickness1, OxyThickness oxyThickness2)
{
    if (oxyThickness1.Left != oxyThickness2.Left)
    {
        return false;
    }

    if (oxyThickness1.Top != oxyThickness2.Top)
    {
        return false;
    }

    if (oxyThickness1.Right != oxyThickness2.Right)
    {
        return false;
    }

    if (oxyThickness1.Bottom != oxyThickness2.Bottom)
    {
        return false;
    }

    return true;
}

bvsms wrote at 2014-03-27 01:14:

objo wrote:
Did you try setting the Width, Height, AutoAdjustPlotMargins and PlotMargins of the Plot control? If you do this, I think the size of the plot should be fixed.
It is easy to add Rendering/Rendered events to the PlotModel, but I would like to avoid it if it is not really needed.
The PlotModel was meant to be the abstraction of the plot view - so it contains both the "plot area" and all the transforms that are related to the size of the view. See also https://oxyplot.codeplex.com/workitem/10133 which is related to this.
Is is possible to fix the width of the x-axis?
For example a plot will display a line series with data that can vary fro 0 to 1000000.
Let's assume we fix the plot width. If the data is within the range 0-10 then the x-axis width will have a certain value. However if we load data in the range between 10000 -100000 then the x-axis width will shrink to accommodate the extra digits displayed on the Y-axis.
It gets even worse if we enable the Y-axis title. (the x-axis shrinks even more.)

In other words rather than fixing the plot width, we need a way of fixing the x-axis width and allow the plot width to move dynamically. Ideally it would be great to anchor the origin of the x-axis as well.

If this is not possible, then having a "rendered" event would allow us to do all the calculations manually to ensure the x-axis has the correct width and location.

override of getHashCode in PlotElement

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

benjaminrupp wrote at 2014-04-15 08:42:

Hi,

what is the reason for overriding GetHashCode in PlotElement?
In my opinion this is really risky cause it is now no more possible to compare, i.e. axes or hold dictionarys of axes.

Best regards

Benjamin

objo wrote at 2014-04-16 08:51:

PlotElement.GetHashCode is used by the HeatMapSeries to check whether the ColorAxis has changed.
Since this is a reference type I guess you have a point, we can change the implementation of HeatMapSeries and revert to the default GetHashCode in PlotElement.

objo wrote at 2014-04-16 09:13:

change committed

2 LineSeries on 2 different YAxis

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

philmo74 wrote at 2011-11-07 19:51:

Hey,

Quick question. How can I make a chart that has two lineseries that have very different scales? How can I assign different y-axis to the two respective lineseries?

 

Thanks in advance.


objo wrote at 2011-11-07 22:26:

see the Amdahl's law example in the Example browser. Set focus on the OxyPlot control and press Ctrl+Alt+C. Paste the source into your code.

Define two vertical axes (at different positions or with different position tiers) and define a Key for each axis. Set the LineSeries.YAxisKey to select which axis to use.


philmo74 wrote at 2011-11-08 15:53:

Great that works!

 

Didn't know you could copy paste the code.

 

Cheers

How to plot DateTime v Value

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

jessimb wrote at 2014-05-26 21:20:

I'm sorry if this is a duplicate. I am struggling to create a plot given a list of Times and Values. The examples have the times in double format, which I'm not sure where that is coming from. Thanks for your help!

Auriou wrote at 2014-05-27 17:56:

Hello, Here is a small example. The principle is to convert the date in double with the static function DateTimeAxis.ToDouble
// Objet (client) with DateTime and double
var objList = new List<Tuple<DateTime, double>>()
 {
     new Tuple<DateTime, double>(DateTime.Now, 10),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-1), 20),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-2), 30),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-3), 40),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-4), 50),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-5), 60)
 };

// define an axis Date  
var dateTimeAxis = new DateTimeAxis()
 {
    Title = "Date",
    Position = AxisPosition.Bottom,
    IntervalType = DateTimeIntervalType.Months,
    StringFormat = "MMM yy"
 };

// Convert object client  to  DataPoint
var points = objList.Select(obj => new DataPoint(DateTimeAxis.ToDouble(obj.Item1), obj.Item2)).ToList();

// Create Line
var linearSeries = new LineSeries("DateLine")
 {
     ItemsSource = points
 };
0

polar plot - which series to use?

Laro88 10 years ago updated 10 years ago 8
Which Series should be used in a polar plot?
I have some polar coordinates in a SortedList<double,double> however scatter and line results in hickups. The samples are heavily focused on Function series, hence not much help there with regards to polar plotting

how to improve wpf plot performance when need draw about 10000 Rectangles

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

ProCodeMyth wrote at 2012-08-15 10:33:

he everyone:

   i need draw 10000-20000 rectangles (color fill) in my wpf appliction (similar  pixel in bitmap ).

the app will became slow , there is a good solution  for draw-heavy  appliction.

i find oxyplotwpf render graphic in ShapesRenderContext, it perform well when  plot element

count is little,  i want to try use drawingRenderContex instead of shapsrenderContex, but i have not success. anyone can help me, thanks in advance

 


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

I did not see any significant performance improvement in the DrawingRenderContext, so this code was just left there in case it should be reviewed again.

I guess you want to plot heat maps? I think it is necessary to support bitmaps in the IRenderContext to get good performance for those. See http://oxyplot.codeplex.com/workitem/9801


ProCodeMyth wrote at 2012-08-23 02:22:

very thank objo,

   your guess is exactly what i want to do, i recently study geogological map , i need fill many fill rectangles with color which represent lith info,   so  i need an way to quick draw , bitmap buffer(bitmap render) is an great idea,  but in wpf  i dont know how to implement ,  WriteableBitmap may help me .


objo wrote at 2012-08-23 08:53:

In WPF it should be easy to implement a heat map using BitmapSource.Create. I think this will have better performance than drawing on a WriteableBitmap. Create a 256-color palette and a pixel array (scaled to 8-bit) from your lithology data. Wrap the image in a WPF ScrollViewer and use a WPF scale transform if you want to zoom in/out!

http://msdn.microsoft.com/en-us/library/ms616045.aspx


ProCodeMyth wrote at 2012-08-23 11:37:

the problem now i face is i hope that i can using BitmapSource in oxyplot system,  using exist function of oxyplot,if i rewritte my code  without help of oxyplot ,it is very difficult for me , i have to  rewrite  coord tranform and many ether  function .


objo wrote at 2012-08-23 15:51:

I added http://oxyplot.codeplex.com/workitem/9985, you see there are some challenges related to the bitmap rendering there...

VS 2012 Express - Nuget Installation

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

tesner wrote at 2013-02-06 11:29:

Hi everyone,

Has anyone got the OxyPlot.Wpf working on VS 2012 Express? I get the following error when trying to install the nuget package:
Error: Could not install package: 'OxyPlot.Core 2013.1.28.1'. You are trying to install this package into a project that targets '.NETFramework, Version=v4.0', but the package does not contain any assembly references that are compatible with taht framework. For more information, contact the package author.
This also happens with .NET 4.5 target. I've tried manually referencing the assemblies. The design time fails to render the Plot control, and indicates that the oxyplot assembly cannot be found, but it works in runtime.

Thanks.

tibel wrote at 2013-02-06 16:12:

You are probably using an old version of NuGet.
OxyPlot.Core is a Portable library project and you need at least NuGet 2.1 for it to work.

tesner wrote at 2013-02-08 08:33:

Hi tibel,
Thanks! Installing the latest NuGet did the trick.