I'd like to create a polar diagram with oxyplot. The circular axis should not consist of integers, but of categories.
Meaning instead of 1 ... 10 it should say Category A Category B ... around the plot.
Neither MagnitudeAxis nor AngularAxis provide the possibility to set "strings" for the axis.
CategoryAxis however cannot be used to plot a polar diagram, because it does not support angles.
My code so far:
var plotModel = new PlotModel { Title = "", };
plotModel.PlotType = OxyPlot.PlotType.Polar;
plotModel.Axes.Add(new OxyPlot.Axes.AngleAxis()
{
MajorGridlineStyle = LineStyle.Solid,
//MinorGridlineStyle = LineStyle.Dot,
MajorStep = 1,
CropGridlines = false,
StartAngle = 450,
EndAngle = 90,
Minimum = 0,
Maximum = 19
});
plotModel.Axes.Add(new OxyPlot.Axes.MagnitudeAxis()
{
MajorGridlineStyle = LineStyle.Solid,
Minimum = 0,
Maximum = 5,
MajorStep = 1,
MinorStep = 1
});
var newValues = new OxyPlot.Series.LineSeries { Title = "New Values", StrokeThickness = 1 };
int i = 0;
foreach(var dataRow in details)
{
newValues.Points.Add(new DataPoint(dataRow.NewValue, i++)); //instead of i++ I would like to put a string of the object dataRow, but this is not supported...
}
In lack of examples and documentation online, this is my last hope to find some help...
It looks to me like the LabelFormatter property is what you need. The code below creates labels 'Category A', 'Category B'...'Category S' around the outside of the plot. It does this because (char)65 is 'A', (char)66 is 'B' etc.
plotModel.Axes.Add(new OxyPlot.Axes.AngleAxis()
{
MajorGridlineStyle = LineStyle.Solid,
MajorStep = 1,
CropGridlines = false,
StartAngle = 450,
EndAngle = 90,
Minimum = 0,
Maximum = 19,
LabelFormatter = d => $"Category {(char)(d+65)}"
});
Based on the answer of Rich N I was able to find a (nasty) workaround by myself:
plotModel.Axes.Add(new OxyPlot.Axes.AngleAxis()
{
MajorGridlineStyle = LineStyle.Solid,
//MinorGridlineStyle = LineStyle.Dot,
MajorStep = 1,
CropGridlines = false,
StartAngle = 450,
EndAngle = 90,
Minimum = 0,
Maximum = 19,
LabelFormatter = d => myCategoryList[Convert.ToInt32(d)] //myCategoryList is a list of strings
});
Related
I'm trying to create a Polar Plot with Oxyplot in my WPF application. I want the MagnitudeAxis to be reversed so I made the StartPosition = 1 and the EndPosition = 0. However this causes the plot not to render. It looks it may be due to the variables a0 and a1 being set to 0 in the UpdateTransform() method in MagnitudeAxis.cs but it may be something else (not exactly sure what all these variables represent).
Here's my code to set up the polar plot:
/// dictionary of angles: magnitudes
dict = {-180: -18, -179: -17.9, ... , 0: 0, ... , 178: -17.8, 179: -17.9}
PlotModel myPlot = new PlotModel
{
Title = "Polar Plot",
PlotType = PlotType.Polar,
PlotAreaBorderThickness = new OxyThickness(0),
};
var series1 = new ScatterSeries
{
Title = "Polar Series",
MarkerType = MarkerType.Circle,
MarkerSize = 3,
MarkerFill = OxyColor.FromRgb(255, 0, 0),
};
var axis1 = new AngleAxis
{
StartPosition = 1,
EndPosition = 0,
StartAngle = 270,
EndAngle = -90,
Title = "Angle",
LabelFormatter = d => $"{d}",
MajorStep = 30,
Minimum = -180,
Maximum = 180,
MinorGridlineStyle = LineStyle.None,
};
var axis2 = new MagnitudeAxis
{
/// here's where I set the Start and End Position
StartPosition = 1,
EndPosition = 0,
MajorStep = 6,
Title = "Magnitude",
MinorGridlineStyle = LineStyle.None,
Minimum = dict.Values.Min();
Maximum = dict.Values.Max()
};
foreach (KeyValuePair<double, double> keyValuePair in dict)
{
series1.Points.Add(new ScatterPoint(keyValuePair.Value, keyValuePair.Key));
}
myPlot.Axes.Add(axis1);
myPlot.Axes.Add(axis2);
myPlot.Series.Add(series1);
This is what I get when the plot tries rendering:
This is what I get when I use default Start/End Positions:
What I want is the default plot with 0 in the center and -18 on the edge instead.
This is my first question ever on SO, so let me know if there's any other information I should provide.
Hello everyone i working in project that convert data (date and value) to graphic curve .
i have problem with x axis the value of date printing in double format , i want this values showing like this format 14:12:35
var gradientBrush = new LinearGradientBrush
{
StartPoint = new System.Windows.Point(0, 0),
EndPoint = new System.Windows.Point(0, 1)
};
gradientBrush.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromRgb(33, 148, 241), 0.2));
gradientBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1));
cartesianChart1.Series.Add(new LineSeries
{
Values = GetData(),
Fill = gradientBrush,
StrokeThickness = 0.9,
PointGeometry = null
});
cartesianChart1.Zoom = ZoomingOptions.X;
private ChartValues<DateTimePoint> GetData()
{
var values = new ChartValues<DateTimePoint>();
for (var i = 0; i <lsTemp.Count(); i++)
{
// System.DateTime.Today.AddDays(i)
values.Add(new DateTimePoint(lsDataTime[i], lsTemp[i]));
}
return values;
}
enter image description here
you need to set LabelFormatter property of Axis class.
Something like this:
AxisX = new Axis
{
Title = "Date",
Separator = new Separator { IsEnabled = false,Step = 1 },
LabelsRotation = -90,
Foreground = new SolidColorBrush(Colors.Black),
LabelFormatter = value => new System.DateTime((long)value).ToString("t")
};
And look at this link for formats ToString data formats
I'm using to Oxyplot for my Xamarin.iOS project for plotting a bar chart
This is what my plot currently looks like
Here I need to hide the Right and top axis
I tried :
model.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Right,
IsAxisVisible = false
});
model.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Top,
IsAxisVisible = false
});
But no effect.. Here's my full code
public MyClass()
{
var model = new PlotModel { Title = "ColumnSeries" };
// A ColumnSeries requires a CategoryAxis on the x-axis.
model.Axes.Add(new CategoryAxis()
{
Position = AxisPosition.Bottom,
MinorTickSize = 0,
//MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Solid,
});
model.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
MinorTickSize = 0,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Solid,
Minimum = 0,
Maximum = 400
});
model.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Right,
IsAxisVisible = false
});
model.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Top,
IsAxisVisible = false
});
var series = new ColumnSeries();
series.Items.Add(new ColumnItem() { Value = 200});
series.Items.Add(new ColumnItem(200));
series.Items.Add(new ColumnItem(300));
series.Items.Add(new ColumnItem(100));
series.Items.Add(new ColumnItem(200));
series.Items.Add(new ColumnItem(100));
series.Items.Add(new ColumnItem(130));
model.Series.Add(series);
this.MyModel = model;
}
How do I do it? Any help is appreciated....
Edit:
Also, In my chart above, why are the y labels not showing. How can I change the x labels like below... Is it possible to draw lines in this chart like below?
This is what I want my final graph to look like:
The problem is that the black border you are currently seeing is not the axis, is the plot area border, so you have to modify this property in the plotmodel:
model.PlotAreaBorderColor = OxyColors.Transparent;
And then, you have to add the AxisLineStyle to the axis that you want to draw(left and bottom), like this:
model.Axes.Add(new LinearAxis()
{
AxislineStyle = LineStyle.Solid,
Position = AxisPosition.Left,
MinorTickSize = 0,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Solid,
Minimum = 0,
Maximum = 400
});
When reducing charts the candle begins to overlap another candle.
For example
Axises
DateTimeAxis timeSPanAxis1 = new DateTimeAxis()
{
Position = AxisPosition.Bottom,
MinorIntervalType = DateTimeIntervalType.Auto,
MajorGridlineStyle = LineStyle.Dot,
MinorGridlineStyle = LineStyle.Dot,
MajorGridlineColor = OxyColor.FromRgb(44, 44, 44),
TicklineColor = OxyColor.FromRgb(82, 82, 82)
};
PlotModel.Axes.Add(timeSPanAxis1);
LinearAxis linearAxis1 = new LinearAxis()
{
Position = AxisPosition.Right,
MajorGridlineStyle = LineStyle.Dot,
MinorGridlineStyle = LineStyle.Dot,
MajorGridlineColor = OxyColor.FromRgb(44, 44, 44),
TicklineColor = OxyColor.FromRgb(82, 82, 82)
};
PlotModel.Axes.Add(linearAxis1);
and candle stick series
CandleStickSeries candle = new CandleStickSeries()
{
Color = OxyColors.Black,
IncreasingColor = OxyColor.FromRgb(0,197,49),
DecreasingColor = OxyColor.FromRgb(255,95,95),
DataFieldX = "Time",
DataFieldHigh = "H",
DataFieldLow = "L",
DataFieldClose = "C",
DataFieldOpen = "O",
TrackerFormatString = "Date: {2}\nOpen: {5:0.00000}\nHigh: {3:0.00000}\nLow: {4:0.00000}\nClose: {6:0.00000}",
};
Why is this happening? How to fix it?
I just fixed the issue concerning the doji candles.
The pull request can be found on
GitHub.
Can anyone tell me how to change the Y axis string format??
I have Y-Axis percentages that I want to add the percent sign to.
I am using OxyPlot to produce the chart in wpf.
Here is my attempt, but it is NOT working:
Func<double, string> formatFunc = (x) => string.Format("{000.00}%", x);
formatFunc = new Func<double,string>("{0}");
// Add the plot to the window
line.YAxis.LabelFormatter = formatFunc;
This produces null reference error.
Thanks!
This is an example I've used previously to format the x-axis on an oxy-plot:
var xAxis = new DateTimeAxis
{
Position = AxisPosition.Bottom,
StringFormat = "dd/MM/yyyy",
Title = "End of Day",
IntervalLength = 75,
MinorIntervalType = DateTimeIntervalType.Days,
IntervalType = DateTimeIntervalType.Days,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.None,
};
Plot = new PlotModel();
Plot.Axes.Add(xAxis);
this._PlotModel.Axes.Add( new LinearAxis
{
Position = AxisPosition.Left,
Minimum = 0.025,
Maximum = 0.205,
StringFormat = "0.00%",
MajorStep = 0.005
} );
- add percents as ratio: 20.5% --> 0.205, 0.5% --> 0.005, etc.