When trying to plot candlestick chart using Oxyplot library, it is empty, despite the fact that I assigned model to the plot view.
var plotModel1 = new PlotModel { Title = "Large Data Set (wide window)" };
var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom };
plotModel1.Axes.Add(timeSpanAxis1);
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
plotModel1.Axes.Add(linearAxis1);
var n = 10000;
var items = HighLowItemGenerator.MRProcess(n).ToArray();
var series = new CandleStickSeries
{
Color = OxyColors.Black,
IncreasingColor = OxyColors.DarkGreen,
DecreasingColor = OxyColors.Red,
DataFieldX = "Time",
DataFieldHigh = "H",
DataFieldLow = "L",
DataFieldOpen = "O",
DataFieldClose = "C",
TrackerFormatString =
"High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
ItemsSource = items
};
timeSpanAxis1.Minimum = items[n - 200].X;
timeSpanAxis1.Maximum = items[n - 130].X;
linearAxis1.Minimum = items.Skip(n - 200).Take(70).Select(x => x.Low).Min();
linearAxis1.Maximum = items.Skip(n - 200).Take(70).Select(x => x.High).Max();
plotModel1.Series.Add(series);
timeSpanAxis1.AxisChanged += (sender, e) => AdjustYExtent(series, timeSpanAxis1, linearAxis1);
var controller = new PlotController();
controller.UnbindAll();
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
plotView1.Model = plotModel1;
Strange thing is that I've just copied few things from the Oxyplot series example. I've also created minimal project with the problem described.
The objects generated by the HighLowItemGenerator have different names of properties than defined in the CandleStickSeries definition. Check the items objects in the debugger to see it. Maybe the sample is a bit out of date. The solution is to change the series definition to use the correct properties this is how it should look like:
var series = new CandleStickSeries
{
Color = OxyColors.Black,
IncreasingColor = OxyColors.DarkGreen,
DecreasingColor = OxyColors.Red,
DataFieldX = "X",
DataFieldHigh = "High",
DataFieldLow = "Low",
DataFieldOpen = "Open",
DataFieldClose = "Close",
TrackerFormatString =
"High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
ItemsSource = items
};
Related
When a value of -1e8 is added to a StackedColumnSeries in a SKCartesianChart, the value is labelled with -100000000000000 μ instead of -100 M as expected.
I suspect this is a bug in the prerelease version of livecharts. I've reported it, but thought to ask here in case anyone's seen the same problem and has a workaround.
var chart = new SKCartesianChart
{
Series = new List<ISeries>
{
new StackedColumnSeries<decimal> {Values = new [] {1e8m}},
new StackedColumnSeries<decimal> {Values = new [] {-1e8m}}, // -100000000000000 μ
}
};
Thanks for the report on Github, this is a bug, it is already fixed, and this fix fill be included in the next version of the library.
For now, you can build your own formatter in the YAxis:
var chart = new SKCartesianChart
{
Series = new List<ISeries>
{
new StackedColumnSeries<decimal> {Values = new [] {1e8m}},
new StackedColumnSeries<decimal> {Values = new [] {-1e8m}}
},
YAxes = new[]
{
new Axis
{
Labeler = value =>
{
var l = value == 0 ? 0 : (int)Math.Log10(Math.Abs(value));
if (l >= 6)
{
value /= Math.Pow(10, 6);
return value.ToString($"######0.####### M");
}
return value.ToString($"######0.#######");
}
}
}
};
my intention is to display a gps track and the corresponding trackpoints with Mapsui (wpf) on a map. I tried the following code. The result is that the blue linestring is displayed (ok), the red track points (ok) but for any reason you see white track points which are very large and I do not want them to appear at the map and I do not know where the white dots are coming from. Any idea what I am doing wrong?
protected ILayer CreateLineStringLayer(String name, List<GeoWaypoint> geoWaypoints)
{
var lineString = new LineString();
List<Feature> featureList = new List<Feature>();
IStyle pointStyle = new SymbolStyle()
{
SymbolScale = 0.30,
Fill = new Brush(Mapsui.Styles.Color.FromString("Red"))
};
foreach (var wp in geoWaypoints)
{
var point = SphericalMercator.FromLonLat(wp.Longitude, wp.Latitude);
lineString.Vertices.Add(point);
var p2 = SphericalMercator.FromLonLat(wp.Longitude, wp.Latitude);
var pointFeature = new Feature();
pointFeature.Geometry = p2;
pointFeature.Styles.Add(pointStyle);
featureList.Add(pointFeature);
}
IStyle linestringStyle = new VectorStyle()
{
Fill = null,
Outline = null,
Line = { Color = Mapsui.Styles.Color.FromString("Blue"), Width = 4 }
};
Feature lineStringFeature = new Feature()
{
Geometry = lineString
};
lineStringFeature.Styles.Add(linestringStyle);
featureList.Add(lineStringFeature);
MemoryProvider memoryProvider = new MemoryProvider(featureList);
return new MemoryLayer
{
DataSource = memoryProvider,
Name = name
};
}
so for everyone who is interest in the answer
return new MemoryLayer
{
DataSource = memoryProvider,
Name = name ,
Style = null
};
You need to set the value for Style to null for the Memorylayer
Im not sure im doing something fairly simple wrong. Im getting below plot when using the below code. I was expecting to get the B values in its own column like you would in excel.
EDIT: I have added my config in the post also, if there are some properties that im missing
/Thomas
BarDataset<double> _barDataSet3 = new BarDataset<double>
{
Label = "A",
BackgroundColor = ColorUtil.RandomColorString(),
BorderWidth = 0,
HoverBackgroundColor = ColorUtil.RandomColorString(),
HoverBorderColor = ColorUtil.RandomColorString(),
HoverBorderWidth = 1,
BorderColor = "#ffffff"
};
_barChartConfig.Data.Labels.AddRange(new[] { "A"});
_barDataSet3.Add(2.6);
_barChartConfig.Data.Datasets.Add(_barDataSet3);
BarDataset<double> _barDataSet4 = new BarDataset<double>
{
Label = "B",
BackgroundColor = ColorUtil.RandomColorString(),
BorderWidth = 0,
HoverBackgroundColor = ColorUtil.RandomColorString(),
HoverBorderColor = ColorUtil.RandomColorString(),
HoverBorderWidth = 1,
BorderColor = "#ffffff"
};
_barChartConfig.Data.Labels.AddRange(new[] { "B" });
_barDataSet4.Add(4.5);
_barChartConfig.Data.Datasets.Add(_barDataSet4);
EDIT: My config - is there a property that im missing?:
_barChartConfig = new BarConfig
{
Options = new BarOptions
{
Title = new OptionsTitle
{
Display = true,
Text = "Simple Bar Chart"
},
Scales = new BarScales
{
XAxes = new List<CartesianAxis>
{
new BarCategoryAxis
{
BarPercentage = 0.5,
BarThickness = BarThickness.Flex
}
},
YAxes = new List<CartesianAxis>
{
new BarLinearCartesianAxis
{
Ticks = new LinearCartesianTicks
{
BeginAtZero = true
}
}
}
}
}
};
I'm stuck on this problem with a ComboBox.
I need to create it programmatically, set a DataSource, add it to my form and then change the SelectedIndex. I'm doing it like this:
rectangle = new Rectangle(x, y, width, height)
ComboBox cb = new ComboBox
{
Size = Rectangle.Size,
Location = Rectangle.Location,
DataSource = new List<string>(comboBoxDataSource),
};
Form1.Controls.Add(cb);
cb.SelectedIndex = index;
When the program gets to that last line, i throws an error saying:
System.ArgumentOutOfRangeException: 'InvalidArgument=Value of '4' is
not valid for 'SelectedIndex'. Parameter name: SelectedIndex'
When the code crash I can see that the ComboBox contains 6 items, so shouldn't index '4' be valid at this point?
I have read some articles and other questions about the problem, but nothing I have found have worked. I think it's because the form doesn't create a handle for the ComboBox, before I try to change the index.
Is there anyone who have had a similar problem, or know a solution?
Bind the datasource after you add your combobox to the control. Then you can select an item.
var dataSource = new List<string> { "one", "two", "three", "four", "five" };
var rectangle = new Rectangle(10, 10, 100, 40);
ComboBox cb = new ComboBox
{
Location = rectangle.Location,
Size = rectangle.Size,
};
this.Controls.Add(cb);
cb.DataSource = new List<string>(dataSource);
cb.SelectedIndex = 3;
Add a BindingSource and set its DataSource. Add a binding context to the combobox and after that set the combobox DataSource to the BindingSource.DataSource. See below:
string[] dataSource = new string[30];
for (int i = 0; i < 30; i++) {
dataSource[i] = "test " + i.ToString();
}
ComboBox cb = new ComboBox();
cb.Size = new Size(121, 21);
cb.Location = new Point(55, 74);
BindingSource bS = new BindingSource();
cb.BindingContext = new BindingContext();
bS.DataSource = dataSource;
cb.DataSource = bS.DataSource;
cb.SelectedIndex = 4; // shoul and does display test 3
this.Controls.Add(cb);
I have a oxyplot column series which I have masked as a histogram using a linear axis. I get my values from a list called frequency with 20 elements.
I wonder if there is a smarter way to do this:
this.Items = new Collection<Item>
{
new Item {Label = "1", Value=frequency[0]},
new Item {Label = "2", Value=frequency[1]},
new Item {Label = "3", Value=frequency[2]},
...
new Item {Label = "18", Value=frequency[17]},
new Item {Label = "19", Value=frequency[18]},
new Item {Label = "20", Value=frequency[19]},
};
I have tried to create a for-loop inside like this:
this.Items = new Collection<Item>
{
for (int i = 0; i < 20; i++)
{
Items.Add(new Item { Label = i.ToString(), Value = frequency[i]});
}
};
But it does not work.
Does anyone have an idea on how to do this?
You can't put the for loop in the object initializer.
Create the collection.
this.Items = new Collection<Item>();
Populate it:
for (int i = 0; i< 20; i++)
{
Items.Add(new Item { Label = i.ToString(), Value = frequency[i] });
}