Change Oxyplot Axisline color - c#

I create a new Plot and its PlotModel with a black BackgroundColor
Then I create a new Axes. The X-Axis doesn't matter, it's invisible.
The Y-Axis is:
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
AxislineThickness = 2,
AxislineColor = OxyColors.White,
MinorGridLinethickness = 2,
MajorGridLineThickness = 2,
MinorTickSize = 4,
MajorTickSize = 7,
TicklineColor = OxyColors.White,
FontSize = 40,
TextColor = OxyColors.White
}
Everything works BUT the Y-Axisline. It seems to stay black no matter what. The ticks starting 1-2 pixels on the left of where the line should be are white and have the correct length.
Is this the wrong parameter?

The trick was Undefined.
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
LineStyle = LineStyle.Undefined
};
Somehow this is a visible, editable, continuous line.

If you define the axis line you should also hide the border arround plot area, because it is drawn over the axis line.
using model.PlotAreaBorderThickness = 0

Related

Add grid lines to y-axis in NPOI bar chart

I'd like to add horizontal grid lines to a bar chart (IChart) I created using NPOI. I can't find anything in the documentation about adding grid lines to a chart, and I'm wondering if I'm missing something. My code is shown below:
IDrawing drawing = sheet.CreateDrawingPatriarch();
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 4, chartRow, 10, chartRow + 30);
IChart chart = drawing.CreateChart(anchor);
IBarChartData<string, double> data = chart.ChartDataFactory.CreateBarChartData<string, double>();
IChartAxis xAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
xAxis.MajorTickMark = AxisTickMark.None;
xAxis.MinorTickMark = AxisTickMark.None;
IValueAxis yAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
yAxis.MajorTickMark = AxisTickMark.Cross;
yAxis.MinorTickMark = AxisTickMark.None;
yAxis.Crosses = AxisCrosses.AutoZero;
yAxis.SetCrossBetween(AxisCrossBetween.Between);
IChartDataSource<string> xSource = DataSources.FromStringCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 0, 0));
IChartDataSource<double> ySource = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 1, 1));
IBarChartSeries<string, double> series = data.AddSeries(xSource, ySource);
series.SetTitle("Matches By World-Check Category"); // This doesn't display for some reason
chart.Plot(data, xAxis, yAxis);
Displaying minor and major gridlines for chart is not supported.
I would suggest to create a ticket for an enhancement.
You can add the gridlines with something like this
chart.GetCTChart().plotArea.valAx[0].AddNewMajorGridlines(); // Alongside Y
chart.GetCTChart().plotArea.catAx[0].AddNewMajorGridlines(); // Alongside X

OxyPlot Change Interval On Zoom Level

I'm trying to make my plot change it's interval type depending on the level of zoom but I'm not sure how to achieve this. I'm using a DateTimeAxis and would like it to start at Days. Then zooming out would change from days to months, finally to years. Zooming in would change from Days to hours, maybe seconds if this type of behavior is even possible.
Currently I have my axes setup as follows:
public DateTimeAxis HorizontalAxis
{
get
{
return new DateTimeAxis
{
Position = AxisPosition.Bottom,
Minimum = DateTimeAxis.ToDouble(Start),
Maximum = DateTimeAxis.ToDouble(End),
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = double.NaN,
MinimumMinorStep = 0,
AbsoluteMinimum = DateTimeAxis.ToDouble(Start),
AbsoluteMaximum = DateTimeAxis.ToDouble(End),
MinorIntervalType = DateTimeIntervalType.Hours,
IntervalType = DateTimeIntervalType.Days,
Title = " Date Time Axis Title "
};
}
}
public LinearAxis VerticalAxis
{
get
{
return new LinearAxis
{
Position = AxisPosition.Left,
Minimum = SetPoint - 4,
Maximum = SetPoint + 4,
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = 0.5,
MinimumMinorStep = 0,
AbsoluteMinimum = SetPoint - 4,
AbsoluteMaximum = SetPoint + 4,
MinorTickSize = 0,
Title = " Linear Axis Title "
};
}
}
If this type of behavior is not possible I would also ask if there is a way to get hours to show when zooming in from days. When making a default plot this was the behavior I saw.
Thanks!
I know I just posted this question but perhaps there are other people who are interested in getting this type of behavior.
To dynamically change the axis I used the AxisChanged event described Here
From there I created an output message to see what properties were changing in the axes. I found that the Scale, Minor Step Size, and Major Step Size are what changes on zooming. Implementing a simple if statement to check the scale I was able to get the behavior I desired.
private async void Horizontal_AxisChanged(object sender, AxisChangedEventArgs e)
{
DateTimeAxis horizontal = sender as DateTimeAxis;
if(horizontal.Scale > 100)
{
horizontal.IntervalType = DateTimeIntervalType.Hours;
}
else if(horizontal.Scale < 100)
{
horizontal.IntervalType = DateTimeIntervalType.Days;
}
}

How to prevent axis from auto-scaling?

Each time I add new data to series, Y axis is panning/zooming automatically in order to fit new data into screen. How can I prevent Oxyplot from touching the axis? I would like to have the scale fixed all the time, no matter what data I feed to plot
As #Taw stated, the properties in oxyplot are the same:
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 10,
});
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Bottom,
Minimum = 0,
Maximum = 10,
});

C# Excel Chart can't set serie scale

I'm trying to draw a threshold (1 line from left to right). To do so I add the threshold value twice and the value 0 and 1 for xValues then set the scale of X to be from 0 to 1.
public static void AddThreshold(Chart xlChart, double value, string name, int color, bool secondary)
{
Series series = xlChart.SeriesCollection().NewSeries();
series.Name = name;
series.XValues = new List<int>() { 0, 1 }.ToArray();
series.Values = new List<double>() { value, value }.ToArray();
Axis xAxis, yAxis;
if (secondary)
{
series.AxisGroup = XlAxisGroup.xlSecondary;
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlSecondary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlSecondary);
}
else
{
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
}
xAxis.MinimumScale = 0;//getting COM error here
xAxis.MaximumScale = 1;
yAxis.Delete();
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
series.MarkerSize = 3;
series.Border.LineStyle = XlMarkerStyle.xlMarkerStyleDash;
series.Border.Color = color;
}
But I'm always getting a COM error and can't figure out the problem. To make things more annoying the exact method was working in a different project (don't ask about it because the code there was partially deleted by mistake and I am not rewriting it).
You can't set min and max of an axis if it's not a value type of axis, and only XY Scatter charts have an X axis that is a value axis. You need to specify the chart type of the added series as XY Scatter before setting the axis scale.
So move this:
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
above this:
xAxis.MinimumScale = 0;

Is it possible to create zedgraph vertical marker?

I wonder, is it possible to create vertical marker in zedgraph?
I want to render all chart points and make vertical marker as indicator of current position.
On a previous project, I used the following code to get that kind of effect.
int i = myPane.AddYAxis("");
myPane.YAxisList[i].Color = Color.Orange;
myPane.YAxisList[i].Scale.IsVisible = false;
myPane.YAxisList[i].MajorTic.IsAllTics = false;
myPane.YAxisList[i].MinorTic.IsAllTics = false;
myPane.YAxisList[i].Cross = pointOnXAxisThatIWantToMark;
In this case I add two axis to mark certain limits on my graph.
You can set the SymbolType of your curve to SymbolType.VDash.
For example, to set the symbol for a LineItem, you can either do it directly in the constructor (curve1 in the source code below), or you can customize it before assigning it to the curve (curve2).
This code:
var curve1 = new LineItem(null, new[] { 0.1, 0.5, 0.9 },
new[] { 0.8, 0.3, 0.1 }, Color.Blue, SymbolType.VDash);
zedGraphControl1.GraphPane.CurveList.Add(curve1);
var curve2 = new LineItem(String.Empty)
{
Points = new PointPairList(
new[] { 0.1, 0.5, 0.9 }, new[] { 0.2, 0.5, 0.9 }),
Color = Color.Red,
Symbol = new Symbol(SymbolType.VDash, Color.Black)
{ Size = 20f, Border = new Border(Color.Black, 6f)}
};
zedGraphControl1.GraphPane.CurveList.Add(curve2);
produces the following graph:

Categories