Display Linestring and Trackpoints with Mapsui - c#

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

Related

Chartsjs (blazor) BarChart not alinged

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
}
}
}
}
}
};

Styles in Excel using Open XML

I am quite new to C# & got stuck with a problem.
I am trying to add some style to the Excel using OpenXML, though it is not drawing borders, the fills (foreground & background colors) and alignment to the cells. I tried many times with different ways, though I am not able to do so.
The following code is not generating any error. Compiling successfully, however not giving the expected output.
Following is the actual output:
Actual Output
Following is the expected output:
Expected Output
The requirement is that only the top row to have this specific style, how can I achieve it?
Any guidance would be greatly appreciated.
Code snippet:
private void ExportDataSet()
{
WorkbookStylesPart wbsp = workbookPart.AddNewPart<WorkbookStylesPart>();
wbsp.Stylesheet = CreateStylesheet();
wbsp.Stylesheet.Save();
}
private static DocumentFormat.OpenXml.Spreadsheet.Stylesheet CreateStylesheet()
{
DocumentFormat.OpenXml.Spreadsheet.Stylesheet stylesheet1 = new DocumentFormat.OpenXml.Spreadsheet.Stylesheet();
#region Font
DocumentFormat.OpenXml.Spreadsheet.Fonts fonts = new DocumentFormat.OpenXml.Spreadsheet.Fonts() { Count = (DocumentFormat.OpenXml.UInt32Value)2U};
// FontID = 0 (The Default Font)
DocumentFormat.OpenXml.Spreadsheet.Font font0 = new DocumentFormat.OpenXml.Spreadsheet.Font();
DocumentFormat.OpenXml.Spreadsheet.FontSize fontSize0 = new DocumentFormat.OpenXml.Spreadsheet.FontSize() { Val = 11D };
DocumentFormat.OpenXml.Spreadsheet.Color color0 = new DocumentFormat.OpenXml.Spreadsheet.Color() { Theme = (DocumentFormat.OpenXml.UInt32Value)1U };
DocumentFormat.OpenXml.Spreadsheet.FontName fontName0 = new DocumentFormat.OpenXml.Spreadsheet.FontName() { Val = "Calibri" };
font0.Append(fontSize0);
font0.Append(color0);
font0.Append(fontName0);
// FontID = 1
DocumentFormat.OpenXml.Spreadsheet.Font font1 = new DocumentFormat.OpenXml.Spreadsheet.Font();
DocumentFormat.OpenXml.Spreadsheet.FontSize fontSize1 = new DocumentFormat.OpenXml.Spreadsheet.FontSize() { Val = 12D };
DocumentFormat.OpenXml.Spreadsheet.FontName fontName1 = new DocumentFormat.OpenXml.Spreadsheet.FontName() { Val = "Calibri" };
DocumentFormat.OpenXml.Spreadsheet.Color color1 = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new DocumentFormat.OpenXml.HexBinaryValue("5B9BD5") };
DocumentFormat.OpenXml.Spreadsheet.Bold bold1 = new DocumentFormat.OpenXml.Spreadsheet.Bold() { Val = true };
// Foreground & Background not working
DocumentFormat.OpenXml.Spreadsheet.ForegroundColor foregroundColor1 = new DocumentFormat.OpenXml.Spreadsheet.ForegroundColor() { Rgb = new DocumentFormat.OpenXml.HexBinaryValue("FF00FF00") };
DocumentFormat.OpenXml.Spreadsheet.BackgroundColor backgroundColor1 = new DocumentFormat.OpenXml.Spreadsheet.BackgroundColor() { Rgb = new DocumentFormat.OpenXml.HexBinaryValue("FF00FF00") };
font1.Append(fontSize1);
font1.Append(fontName1);
font1.Append(color1);
font1.Append(bold1);
font1.Append(foregroundColor1);
font1.Append(backgroundColor1);
fonts.Append(font1);
int fontIndex = fonts.Count() - 1;
#endregion
#region CellBorders
DocumentFormat.OpenXml.Spreadsheet.Borders borders = new DocumentFormat.OpenXml.Spreadsheet.Borders() { Count = (DocumentFormat.OpenXml.UInt32Value)2U };
// Border ID = 0 (The Default Border)
DocumentFormat.OpenXml.Spreadsheet.Border border0 = new DocumentFormat.OpenXml.Spreadsheet.Border();
DocumentFormat.OpenXml.Spreadsheet.LeftBorder leftBorder0 = new DocumentFormat.OpenXml.Spreadsheet.LeftBorder();
DocumentFormat.OpenXml.Spreadsheet.RightBorder rightBorder0 = new DocumentFormat.OpenXml.Spreadsheet.RightBorder();
DocumentFormat.OpenXml.Spreadsheet.TopBorder topBorder0 = new DocumentFormat.OpenXml.Spreadsheet.TopBorder();
DocumentFormat.OpenXml.Spreadsheet.BottomBorder bottomBorder0 = new DocumentFormat.OpenXml.Spreadsheet.BottomBorder();
border0.Append(leftBorder0);
border0.Append(rightBorder0);
border0.Append(topBorder0);
border0.Append(bottomBorder0);
// Border ID = 1
DocumentFormat.OpenXml.Spreadsheet.Border border1 = new DocumentFormat.OpenXml.Spreadsheet.Border();
DocumentFormat.OpenXml.Spreadsheet.LeftBorder leftBorder = new DocumentFormat.OpenXml.Spreadsheet.LeftBorder() { Style = DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thick };
DocumentFormat.OpenXml.Spreadsheet.RightBorder rightBorder = new DocumentFormat.OpenXml.Spreadsheet.RightBorder() { Style = DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thick };
DocumentFormat.OpenXml.Spreadsheet.TopBorder topBorder = new DocumentFormat.OpenXml.Spreadsheet.TopBorder() { Style = DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thick };
DocumentFormat.OpenXml.Spreadsheet.BottomBorder bottomBorder = new DocumentFormat.OpenXml.Spreadsheet.BottomBorder() { Style = DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thick };
border1.Append(leftBorder);
border1.Append(rightBorder);
border1.Append(topBorder);
border1.Append(bottomBorder);
borders.Append(border1);
int borderIndex = borders.Count() - 1;
#endregion
#region Fill
DocumentFormat.OpenXml.Spreadsheet.Fills fills = new DocumentFormat.OpenXml.Spreadsheet.Fills() { Count = (DocumentFormat.OpenXml.UInt32Value)3U };
// Fill ID = 0 (The Default Fill)
DocumentFormat.OpenXml.Spreadsheet.Fill fill0 = new DocumentFormat.OpenXml.Spreadsheet.Fill();
DocumentFormat.OpenXml.Spreadsheet.PatternFill patternFill0 = new DocumentFormat.OpenXml.Spreadsheet.PatternFill() { PatternType = DocumentFormat.OpenXml.Spreadsheet.PatternValues.None }; // required, reserved by Excel
fill0.Append(patternFill0);
// Fill ID = 1 (The default fill of Gray)
DocumentFormat.OpenXml.Spreadsheet.Fill fill1 = new DocumentFormat.OpenXml.Spreadsheet.Fill();
DocumentFormat.OpenXml.Spreadsheet.PatternFill patternFill1 = new DocumentFormat.OpenXml.Spreadsheet.PatternFill() { PatternType = DocumentFormat.OpenXml.Spreadsheet.PatternValues.Gray125 }; // required, reserved by Excel
fill1.Append(patternFill1);
// Fill ID = 2
DocumentFormat.OpenXml.Spreadsheet.Fill fill2 = new DocumentFormat.OpenXml.Spreadsheet.Fill();
DocumentFormat.OpenXml.Spreadsheet.PatternFill patternFill2 = new DocumentFormat.OpenXml.Spreadsheet.PatternFill() { PatternType = DocumentFormat.OpenXml.Spreadsheet.PatternValues.Solid }; // customized Pattern value
DocumentFormat.OpenXml.Spreadsheet.ForegroundColor foregroundColorFill2 = new DocumentFormat.OpenXml.Spreadsheet.ForegroundColor() { Rgb = new DocumentFormat.OpenXml.HexBinaryValue("FF00FF00") };
DocumentFormat.OpenXml.Spreadsheet.BackgroundColor backgroundColorFill2 = new DocumentFormat.OpenXml.Spreadsheet.BackgroundColor() { Rgb = new DocumentFormat.OpenXml.HexBinaryValue("5B9BD500") };
patternFill2.Append(foregroundColorFill2);
patternFill2.Append(backgroundColorFill2);
fill2.Append(patternFill2);
fills.Append(fill2);
int fillIndex = fills.Count() - 1;
#endregion
#region Alignment
DocumentFormat.OpenXml.Spreadsheet.Alignment alignment = new DocumentFormat.OpenXml.Spreadsheet.Alignment()
{
Horizontal = DocumentFormat.OpenXml.Spreadsheet.HorizontalAlignmentValues.Left,
Vertical = DocumentFormat.OpenXml.Spreadsheet.VerticalAlignmentValues.Center
};
#endregion
#region Cell Style Formats & Cell Formats
DocumentFormat.OpenXml.Spreadsheet.CellFormats cellFormats0 = new DocumentFormat.OpenXml.Spreadsheet.CellFormats() { Count = (DocumentFormat.OpenXml.UInt32Value)1U };
// Cell Format ID = 0 (The Default Cell Format)
DocumentFormat.OpenXml.Spreadsheet.CellFormat cellFormat0 = new DocumentFormat.OpenXml.Spreadsheet.CellFormat()
{
NumberFormatId = (DocumentFormat.OpenXml.UInt32Value)0U,
FontId = (DocumentFormat.OpenXml.UInt32Value)0U,
FillId = (DocumentFormat.OpenXml.UInt32Value)0U,
BorderId = (DocumentFormat.OpenXml.UInt32Value)0U,
FormatId = (DocumentFormat.OpenXml.UInt32Value)0U
};
cellFormats0.Append(cellFormat0);
// Cell Format ID = 1
DocumentFormat.OpenXml.Spreadsheet.CellFormat cellFormat1 = new DocumentFormat.OpenXml.Spreadsheet.CellFormat()
{
NumberFormatId = (DocumentFormat.OpenXml.UInt32Value)1U,
FontId = (DocumentFormat.OpenXml.UInt32Value)1U,
FillId = (DocumentFormat.OpenXml.UInt32Value)2U,
BorderId = (DocumentFormat.OpenXml.UInt32Value)1U,
FormatId = (DocumentFormat.OpenXml.UInt32Value)1U,
ApplyBorder = true,
ApplyFont = true,
ApplyFill = true,
};
cellFormats0.Append(cellFormat1);
DocumentFormat.OpenXml.Spreadsheet.CellStyles cellStyles = new DocumentFormat.OpenXml.Spreadsheet.CellStyles() { Count = (DocumentFormat.OpenXml.UInt32Value)1U };
DocumentFormat.OpenXml.Spreadsheet.CellStyle cellStyle = new DocumentFormat.OpenXml.Spreadsheet.CellStyle()
{
Name = "Normal",
FormatId = (DocumentFormat.OpenXml.UInt32Value)0U,
BuiltinId = (DocumentFormat.OpenXml.UInt32Value)1U
};
cellStyles.Append(cellStyle);
#endregion
#region Stylesheet
stylesheet1.Append(fonts);
stylesheet1.Append(fills);
stylesheet1.Append(borders);
stylesheet1.Append(cellFormats0);
stylesheet1.Append(cellStyles);
#endregion
return stylesheet1;
}

Differences between two models

Is there a way to compare 2 models and only show the differences, for example what has been updated, added or deleted?
For example, in the models below, I have created a number of Sample models:
var grocers1 = new List<Grocer>();
var grocer1 = new Grocer
{
Id = 1,
Expenditure = 500,
Name = "Bob"
};
grocers1.Add(grocer1);
var grocers2 = new List<Grocer>();
var grocer2 = new Grocer
{
Id = 1,
Expenditure = 300,
Name = "Bob"
};
grocers2.Add(grocer2);
var fruits = new List<Fruit>();
var fruit1 = new Fruit();
fruits.Add(fruit1);
var orders1 = new List<Order>();
var order1 = new Order
{
Id = 1,
SampleId = 1,
Fruits = fruits
};
var order2 = new Order
{
Id = 1,
SampleId = 1,
Fruits = fruits
};
orders1.Add(order1);
orders1.Add(order2);
var orders2 = new List<Models.Documents.Order> {order1};
var sample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders1
};
var changedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-22"),
Grocers = grocers2,
Orders = orders1
};
var otherChangedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders2
};
So if I compare sample to changedSample it should just show the Date has changed from 2018-10-23 to 2018-10-22 and that the Expenditure has changed from 500 to 300.
Then if I was to compare sample to otherChangedSample it should show that order2 has been removed.
And then finally if I was to compare otherChangedSample to sample it would show that order 2 had been added.
I have tested with AutoMapper this is great for comparing the same base model, excluding lists, it nicely highlights the changes.
I then tried Compare-Net-Objects which is good, this time does take into account lists and highlights the changes, but only if the list count stays the same. It will identify the list count change but not tell you the values of what has been removed or the values of what has been added.
Any help would be much appreciated.
You can use reflection and extension method as well:
var sample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders1
};
var otherChangedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders2
};
class Variance
{
public string Prop { get; set; }
public object valA { get; set; }
public object valB { get; set; }
}
List<Variance> rt = sample.DetailedCompare(otherChangedSample);
using System.Collections.Generic;
using System.Reflection;
static class extentions
{
public static List<Variance> DetailedCompare<T>(this T val1, T val2)
{
List<Variance> variances = new List<Variance>();
FieldInfo[] fi = val1.GetType().GetFields();
foreach (FieldInfo f in fi)
{
Variance v = new Variance();
v.Prop = f.Name;
v.valA = f.GetValue(val1);
v.valB = f.GetValue(val2);
if (!v.valA.Equals(v.valB))
variances.Add(v);
}
return variances;
}
}
have you coded your model classes yourself? If not, then you have to deal with reflection (could be slow and you have to do a lot of programming to cover all data types), or with serialization (serialize as string and do a string compare).
If you can extend your classes, then I would add a method to every single class:
internal void TrackChange(T other, List<Change> changes)
This method in your class Sampe would look like:
void TrackChange(Sample other, List<Change> changes)
{
if (this.Id != other.Id) changes.add(new Change(...));
if (this.Date != other.Date) changes.add(new Change(...));
if (this.Grocers.count != other.Grocers.count) changes.add(new Change(...)); // number of items has changed
for (int i = 0; i < math.min(this.grocers.count, other.grocers.count); i++)
this.grocers[i].TrackChange(other.grocers[i], changes);
....
}
The Grocer class has its onwn TrackChange method. and so on.
This is some coding, but the most efficient and you can handle all cases yourself. for example if the order of grocers in your list does not mind, then you can iterate all grocers of this list and try to find the corresponding grocer in the others list (e.g. by Id) and call the TrackChange then.

Blank chart when using candlesticks

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
};

Change color of bars depending on value in Highchart bar-chart with MVC3

I am using Dotnet Highchart with MVC3
I am currently working with a diagram that looks like this:
I am trying to modify my code so I can change color on the bars depending on what number they have. I also wonder how I can remove the button "Snittbetyg" as you see can on the image.
This is my code:
public ActionResult OfficeStatistic()
{
{
Highcharts chart1 = new Highcharts("chart1")
.SetXAxis(new XAxis { Categories = new[] { "Ödmjukhet", "Engagemang", "Kompetens", "Lönsamhet" } })
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Betygskalan" } })
.SetSeries(new Series { Data = new Data(new object[] { 1, 8, 9, 6 }), Name = "Snittbetyg" })
.SetTitle(new Title { Text = "Örebro Statistik" })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column });
return View(chart1);
}
}
Any kind of help is appreciated.
Thanks in advance!
I haven't used Highchart but you can download examples from their codeplex page. It looks like both of your requirements can be achieved easily.
Remove the "Snittbetyg" button
Disable the legend:
.SetLegend(new Legend { Enabled = false });
Add Colours
For the series data use points instead of just the numbers:
Data data = new Data(new[]
{
new Point { Y = 1, Color = System.Drawing.Color.Red },
new Point { Y = 8, Color = System.Drawing.Color.Blue },
new Point { Y = 9, Color = System.Drawing.Color.Green },
new Point { Y = 6, Color = System.Drawing.Color.Black }
});
Highcharts chart1 = new Highcharts("chart1")
.SetXAxis(new XAxis { Categories = new[] { "Ödmjukhet", "Engagemang", "Kompetens", "Lönsamhet" } })
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Betygskalan" } })
.SetSeries(new Series { Data = data, Name = "Snittbetyg" })
.SetTitle(new Title { Text = "Örebro Statistik" })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetLegend(new Legend { Enabled = false });
There doesn't seem to be a built in way to make highchart automatically colour the bar based on the y-value. I believe you would have to pick the colour yourself, e.g:
private System.Drawing.Color GetBarColour(int value)
{
if (value < 5) return System.Drawing.Color.Red;
if (value > 7) return System.Drawing.Color.Green;
return System.Drawing.Color.Orange;
}
public ActionResult OfficeStatistic()
{
{
var dataItems = new[] {1, 8, 9, 6};
Data data = new Data(
dataItems.Select(y => new Point {Color = GetBarColour(y), Y = y}).ToArray()
);
Highcharts chart1 = new Highcharts("chart1")
.SetXAxis(new XAxis { Categories = new[] { "Ödmjukhet", "Engagemang", "Kompetens", "Lönsamhet" } })
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Betygskalan" } })
.SetSeries(new Series { Data = data, Name = "Snittbetyg" })
.SetTitle(new Title { Text = "Örebro Statistik" })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetLegend(new Legend { Enabled = false });
First, define a Tuple list first item is for color and second item point value
List<Tuple<string, Object>> dataItems = new List<Tuple<string, Object>>();
i am passing value with swtich it is not neccessary
SqlDataReader reader = myComm.ExecuteReader();
if (reader.HasRows)
{
string colorName ="";
while (reader.Read())
{
switch ((string)reader.GetValue(1))
{
case "Total Employee(s)":
colorName = "Blue";
break;
case "Present":
colorName = "Green";
break;
case "Late":
case"Absent":
case "During Less":
case "Early Going":
colorName = "Red";
break;
case "Leave":
colorName = "Orange";
break;
default:
colorName = "Gray";
break;
}
dataItems.Add(new Tuple<string, Object>(colorName, reader.GetValue(2)));
}
Now, Finally add Data into series object
new Series{
Name = "Employees",
Data = new Data(
dataItems.Select(y => new Point {
Color = System.Drawing.Color.FromName(y.Item1),
Y = (int)y.Item2 }).ToArray()
)
}

Categories

Resources