How can I make OxyPlot adjust zoom when calling PlotView.Invalidate? - oxyplot

I have a problem with OxyPlot which is as follows:
I create a new PlotView and attach a PlotModel with some axes when my program starts.
In my program, the user can open a file, which is interpreted and plotted in the PlotView control.
To display the new Series, I do
myPlotView.Invalidate(true);
This will display the data on in the plot, however OxyPlot does not perform any zooming. How can I pan and zoom automatically, such that the plot covers the whole PlotView?
I tried to set
myPlotView.Model.Axes[0].DataMinimum = someValue1
myPlotView.Model.Axes[1].DataMinimum = someValue2
myPlotView.Model.Axes[0].DataMaximum = someValue3
myPlotView.Model.Axes[1].DataMaximum = someValue4
but nothing happens.

Axes calculates the ViewMinimum and ViewMaxium (the real thing you are watching) only if Minimum and Maximum are not specified, you can set them to Double.NaN before resetting, so the ViewMinimum and ViewMaximum will be calculated based on DataMinimum and DataMaximum
foreach (var ax in _plotModel.Axes)
ax.Maximum = ax.Minimum = Double.NaN;
PlotView.ResetAllAxes();
Also if you changed the data points, you must call to Plot.InvalidatePlot() so the DataMinimum and DataMaximum gets updated too.

Do a Axis reset and update the Minimum/Maximum of each Axis.
e.g.
PlotView.ActualModel.Axes[0].Reset();
PlotView.ActualModel.Axes[1].Reset();
PlotView.ActualModel.Axes[0].Minimum = 50;
PlotView.ActualModel.Axes[0].Maximum = 250;
PlotView.ActualModel.Axes[1].Minimum = 50;
PlotView.ActualModel.Axes[1].Maximum = 250;
PlotView.InvalidatePlot(true);
you should of course use the min/max value from your data.

Related

OxyPlot.Wpf integer axis - no MinimumMajorStep property

I am using OxyPlot.Wpf and have a need for an axis that will only show integer major steps.
OxyPlot.Wpf.Axis does not have a MinimumMajorStep (which OxyPlot.Axis has). Is there a simple way to achieve the required objective?
I found the answer:
OxyPlot.Wpf.Axis has a public member InternalAxis, which is a OxyPlot.Axis so all I had to do is add the following code somewhere appropriate:
axis.InternalAxis.MinimumMajorStep = 1;
I believe I understood your question correctly. You could make use of the MajorStep property of the axis for the purpose.
For example, from Xaml
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Bottom" MajorStep="5" Minimum="0" Maximum="100"/>
</oxy:Plot.Axes>
Or from ViewModel
var yAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Maximum = 100,
Minimum = 0,
MajorStep = 5
};
You could additionally set MinorStep="5" (same value as MajorStep) if you would like to the Minor Ticks as well.

OxyPlot how to add Points to DataPoint?

i have a plotmodel with 2 different lineSeries.
In the first lineSeries can be values between 1000 and 10000.
In the second lineSeries are values between 1 and 10.
So when i plot this I can see the first lineSeries very well, but the second one is just at the bottom.
So I defined two different LinearAxis, one for the right and one for the left side.
m.Axes.Add(new LinearAxis { Position = AxisPosition.Left,Minimum = 0, Maximum = maxPointValue1 });
m.Axes.Add(new LinearAxis { Position = AxisPosition.Right, Minimum = 0, Maximum = maxPointValue2 });
Is it possible to bind the first series to the left LinearAxis and the second to the right Axis?
So that the second series is not at the bottom?
Thanks in advance
Michael
Indeed there is my friend.
On your second axis, this case your right, you need to define a key.
var rightAxis = new OxyPlot.Axes.LinearAxis()
{
Key = "secondary",
Position = AxisPosition.Right,
// And then the rest
}
Now when you include a series, you give that the same key
yourLineSeries.XAxisKey = "secondary";
Now when your series is added, it should use your right axis.
Hope this helps!

Why are the colors correct but not the labels in the legend on Dojo StackedColumn

I have an issue with the Legend on a StackedColumn chart. I have set the following dataSeries and legend elements.
In the code, I have the following for loop to assign all the labels to the values so that they appear in the legend.
v = compositeData.dataSeries;
y = compositeData.legend;
for (i = 0; i < v.length; i++) {
dataSeries = v[i];
r += ' ynchart.addSeries("'+y[i]+'", ['+dataSeries+']);'+#NewLine();
}
When I run the code, I end up with
showing the legend except the order of the labels is not in the order I expected. Element [3] is first, followed by [0], 1 and 2. The color of the elements in the legend are in the correct order but somehow the label is not. I have no code in the script anywhere else that sorts anything. Why is the order of the legend label reordering itself and how do I fix it?
When you specify a parameter in a custom control as "multi-instance" you hand over a java.util.List. The List doesn't guarantee you any delivery sequence and that seems what is happening here. So you are probably better of handing over ONE parameter which you then split(). Of course that leans itself to the potential issue that your label and values get out of sync. So you might want to hand over a complete JSON with all included as parameter. Something like:
{ "values" : { "worldwide" : [10,20,30],
"NA" : [2,10,20],
"Europe" : [4,5,4],
"Japan" : [4,5,6]
}
}
You could consider a function that you hand the names of your fields that returns that string for you.

How to add a text on top of a column with ZedGraph?

How can I add some text on top of a bar in a chart.
This is the code I have to add the bar:
var color = ColorTranslator.FromHtml(row.Colour);
var barItem = graphPane.AddBar(row.Propensity.ToString(), null, Ys.ToArray(), color);
Thank you
Here is a quick example using TextObj to simply add labels to each bar.
GraphPane myPane = zedGraphControl1.GraphPane;
double[] y = { 100, 50, 75, 125 };
BarItem myBar = myPane.AddBar("Data", null, y, Color.Red);
for (int i = 0; i < myBar.Points.Count; i++)
{
TextObj barLabel = new TextObj(myBar.Points[i].Y.ToString(), myBar.Points[i].X, myBar.Points[i].Y + 5);
barLabel.FontSpec.Border.IsVisible = false;
myPane.GraphObjList.Add(barLabel);
}
myBar.Label.IsVisible = true;
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
Of course this just uses the value of the data as the label. If you wanted to use custom labels, you could create a string array or list and use that inside the loop.
Here are some ZedGraph references:
Introduction and examples: http://www.codeproject.com/KB/graphics/zedgraph.aspx
Source code documentation: http://zedgraph.sourceforge.net/documentation/default.html
You need to define AlignH and AlignV in your text object:
TextObj textLabel = new TextObj(value.ToString(), positionX, value, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
AlignV define the position of your value on the bar.
Providing you want the label text to match the value of each bar, then you can do it with a single line of code:
BarItem.CreateBarLabels(graphPane, false, "F0");
Note that the 3rd parameter is a double.ToString format. e.g. "F0" = 12, "F2" = 12.34
However, if you want any flexibity with it then this solution is not ideal. It also doesn't work very well if you have a stacked bar chart, because having any 0 value data will cause labels to overlap and look horrific

How can I do a padding between my highest x-value and the plot's right gap in Highcharts?

I need to delete the margins between my lines and plot gap.
I decided to use the startOnTick and endOnTick property but in this case line's points in the gap are not seen or seen only part of them.
Please, help if you know how, of course)))
You can set maxPadding and minPadding within chart options provided to the constructor.
Or you can use setExtremes(min, max) after instantiate the chart for dynamic values.
var myChart = new Highchart.chart(options),
extremes = myChart.xAxis[0].getExtremes(),
minPadding = 20,
maxPadding = 20;
myChart.xAxis[0].setExtremes(extremes.dataMin - minPadding, extremes.dataMax + maxPadding);