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
});
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.
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
});
I'm trying to have tickmarks at an interval of 50. MajorGrid works fine, but I can not find any way to get the tickmarks of the yAxis align to the gridlines of the majorgrid. Currently I'm using this:
chart.ChartAreas.Add(new ChartArea("statistic")
{
AxisX = ...
AxisY = new Axis
{
MajorGrid =
new Grid
{
Enabled = true,
LineColor = Color.Black,
LineDashStyle = ChartDashStyle.Solid,
Interval = 50,
IntervalOffset = 0
},
Title = yAxisDesc,
Minimum = yAxisRange.Item1,
Maximum = yAxisRange.Item2
}
}
to get this:
I tried modifying MajorTickMark to no avail.
What do I have to change?
Try this:
private void Form1_Load(object sender, EventArgs e)
{
int xmax = 100;
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 50;
chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 50;
chart1.ChartAreas[0].AxisY.LabelStyle.Interval = 50;
for (int x = 1; x < xmax; x++)
chart1.Series[0].Points.AddXY(x, 5 * x);
}
Thanks to jstreet,
I found the following solution:
AxisY =
new Axis
{
MajorGrid =
new Grid
{
Enabled = true,
LineColor = Color.Black,
LineDashStyle = ChartDashStyle.Solid,
Interval = 50,
IntervalOffset = 0
},
Title = yAxisDesc,
Minimum = yAxisRange.Item1,
Maximum = yAxisRange.Item2,
LabelStyle = new LabelStyle{Interval = 50, Enabled=true,IntervalOffset = 0,IsEndLabelVisible = true},
MajorTickMark =
new TickMark
{
Enabled = true,
Interval = 50,
IntervalOffset = 0,
},
}
However, using only MajorTickMark or LabelStyle doesn't result in the desired chart. This is it now:
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.
I am using ZedGraph
http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET?fid=26087&fr=11#xx0xx
and I want to plot vertical bars and then have a horizontal line across the entire plot area.
It only seems to go to the ends of the bars!
I tried to add some x-axis and y-axis values to achieve this effect, but it doesn't work.
Is it possible?
Here is my code:
private void CreateGraph( ZedGraphControl zgc )
{
// get a reference to the GraphPane
GraphPane myPane = zg1.GraphPane;
// Set the Titles
myPane.Title.Text = "My Test Bar Graph";
myPane.XAxis.Title.Text = "Label";
myPane.YAxis.Title.Text = "My Y Axis";
// Make up some random data points
string[] labels = { "Panther", "Lion" };
double[] y = { 100, 115 };
double[] x = {0, 900 };
double[] y4 = { 90, 90};
// Generate a black line with "Curve 4" in the legend
LineItem myCurve = myPane.AddCurve("Curve 4", x, y4, Color.Black, SymbolType.Circle);
// Generate a red bar with "Curve 1" in the legend
BarItem myBar = myPane.AddBar("Curve 1", null, y, Color.Red);
myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
// Fix up the curve attributes a little
myCurve.Symbol.Size = 8.0F;
myCurve.Symbol.Fill = new Fill(Color.White);
myCurve.Line.Width = 2.0F;
// Fix up the curve attributes a little
myCurve.Symbol.Size = 8.0F;
myCurve.Symbol.Fill = new Fill(Color.White);
myCurve.Line.Width = 2.0F;
// Draw the X tics between the labels instead of
// at the labels
myPane.XAxis.MajorTic.IsBetweenLabels = true;
// Set the XAxis labels
myPane.XAxis.Scale.TextLabels = labels;
// Set the XAxis to Text type
myPane.XAxis.Type = AxisType.Text;
// Fill the Axis and Pane backgrounds
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));
// Tell ZedGraph to refigure the
// axes since the data have changed
zg1.AxisChange();
}
I found out that you cannot just put a horizontal line on the bar graph because the x-axis type for this case is not numeric/discrete - it is a Text value.
If you want to put horizontal lines on your bar charts you have to use the combo chart:
http://zedgraph.dariowiz.com/indexd6f1.html?title=Combo_Chart_Demo
This way the x-axis is numeric so you can create any lines you need along with the bars.