OxyPlot Zero Line - charts

We have a simple ColumnChart with positive and negative values.
There is no line across the chart though at the 0 line. How do we enable a zero line across?
See attached image

Assuming that you are using a LinearAxis for Y axis.
All you need to do is add to your LinearAxis.
plotModel.Axes.Add(new LinearAxis()
{
Title = "Percentage",
Position = AxisPosition.Left,
// Magic Happens here we add the extra grid line on our Y Axis at zero
ExtraGridlines = new Double[] { 0 }
});

Take a look at this works for me on Android haven't tested it on IOS:
public static PlotModel Withnegativevalues()
{
var plotModel1 = new PlotModel();
plotModel1.LegendBorderThickness = 0;
plotModel1.LegendOrientation = LegendOrientation.Horizontal;
plotModel1.LegendPlacement = LegendPlacement.Outside;
plotModel1.LegendPosition = LegendPosition.BottomCenter;
plotModel1.Title = "With negative values";
var categoryAxis1 = new CategoryAxis();
categoryAxis1.MinorStep = 1;
categoryAxis1.Labels.Add("Category A");
categoryAxis1.Labels.Add("Category B");
categoryAxis1.Labels.Add("Category C");
categoryAxis1.Labels.Add("Category D");
categoryAxis1.ActualLabels.Add("Category A");
categoryAxis1.ActualLabels.Add("Category B");
categoryAxis1.ActualLabels.Add("Category C");
categoryAxis1.ActualLabels.Add("Category D");
plotModel1.Axes.Add(categoryAxis1);
var linearAxis1 = new LinearAxis();
linearAxis1.MaximumPadding = 0.06;
linearAxis1.MinimumPadding = 0.06;
linearAxis1.ExtraGridlines = new Double[1];
linearAxis1.ExtraGridlines[0] = 0;
plotModel1.Axes.Add(linearAxis1);
var columnSeries1 = new ColumnSeries();
columnSeries1.StrokeThickness = 1;
columnSeries1.Title = "Series 1";
columnSeries1.Items.Add(new ColumnItem(25,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(137,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(18,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(40,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries1);
var columnSeries2 = new ColumnSeries();
columnSeries2.StrokeThickness = 1;
columnSeries2.Title = "Series 2";
columnSeries2.Items.Add(new ColumnItem(-12,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-14,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-120,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-26,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries2);
var columnSeries3 = new ColumnSeries();
columnSeries3.StrokeThickness = 1;
columnSeries3.Title = "Series 3";
columnSeries3.Items.Add(new ColumnItem(21,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(8,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(48,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(3,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries3);
var columnSeries4 = new ColumnSeries();
columnSeries4.StrokeThickness = 1;
columnSeries4.Title = "Series 4";
columnSeries4.Items.Add(new ColumnItem(-8,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-21,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-3,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-48,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries4);
return plotModel1;
}

Related

Hundred thousands of datatable records to PDF in web API

I'm trying to create PDF from the DataTable in web api using ADO.Net. Unfortunately based on filters some times I may get very less records & able to download without any problem. Sometimes may be very huge like 200 thousand of records. When I'm checking in local my system its getting hang while converting the dt to PDF. My code is like below:
private FileContentResult ExportPDF(DataTable dataTable)
{
string Name = "Logs";
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
byte[] content = null;
try
{
string[] columnNames = (from dc in dataTable.Columns.Cast<DataColumn>() select dc.ColumnName).ToArray();
int count = columnNames.Length;
object[] array = new object[count];
dataTable.Rows.Add(array);
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);
int cols = dataTable.Columns.Count;
int rows = dataTable.Rows.Count;
HeaderFooter header = new HeaderFooter(new Phrase(Name), false);
// Remove the border that is set by default
header.Border = iTextSharp.text.Rectangle.TITLE;
// Align the text: 0 is left, 1 center and 2 right.
header.Alignment = Element.ALIGN_CENTER;
pdfDoc.Header = header;
// Header.
pdfDoc.Open();
iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows);
pdfTable.BorderWidth = 1; pdfTable.Width = 100;
pdfTable.Padding = 1; pdfTable.Spacing = 4;
//creating table headers
for (int i = 0; i < cols; i++)
{
Cell cellCols = new Cell();
Chunk chunkCols = new Chunk();
iTextSharp.text.Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.Black);
chunkCols = new Chunk(dataTable.Columns[i].ColumnName, ColFont);
cellCols.Add(chunkCols);
pdfTable.AddCell(cellCols);
}
//creating table data (actual result)
for (int k = 0; k < rows; k++)
{
for (int j = 0; j < cols; j++)
{
Cell cellRows = new Cell();
iTextSharp.text.Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
Chunk chunkRows = new Chunk(dataTable.Rows[k][j].ToString(), RowFont);
cellRows.Add(chunkRows);
pdfTable.AddCell(cellRows);
}
}
pdfDoc.Add(pdfTable);
pdfDoc.Close();
content = mStream.ToArray();
return File(content, "application/pdf", "LogReports.pdf");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

xamarin.ios ios-chart BarChartDataSet

Just port ios-charts v2.2.3.0 from Xamarin Nuget package manager.
public void BarChart(BarChartModel _barChartModel, BarChartView _barChartView, string _fromView, bool animateChart)
{
try {
barChartModel = _barChartModel;
barChartView = _barChartView;
barChartView.SetDrawBarShadowEnabled (false);
barChartView.SetMaxVisibleValueCount (15);
barChartView.SetPinchZoomEnabled (true);
barChartView.SetDrawGridBackgroundEnabled (false);
barChartView.ScaleYEnabled = false;
// Chart axis' layout configurations
ChartXAxis xAxis = barChartView.XAxis;
xAxis.SetLabelPosition (XAxisLabelPosition.Bottom);
xAxis.SetDrawGridLinesEnabled (false);
xAxis.SetLabelTextColor (chartTextColor);
xAxis.SpaceBetweenLabels = 2;
xAxis.SetAvoidFirstLastClippingEnabled (true);
xAxis.SetLabelWidth (30f);
ChartYAxis leftAxis = barChartView.LeftAxis;
leftAxis.SetLabelCount (10, false);
leftAxis.SetLabelPosition (YAxisLabelPosition.OutsideChart);
leftAxis.SpaceTop = 10f;
leftAxis.SetLabelTextColor (chartTextColor);
leftAxis.ValueFormatter = new NSNumberFormatter ();
ChartYAxis rightAxis = barChartView.RightAxis;
rightAxis.SetDrawGridLinesEnabled (false);
rightAxis.SetDrawLabelsEnabled (false);
ChartLegend legend = barChartView.Legend;
legend.SetPosition (ChartLegendPosition.BelowChartCenter);
legend.SetForm (ChartLegendForm.Square);
legend.FormSize = 9f;
legend.SetFormToTextSpace (11f);
legend.XEntrySpace = 15f;
legend.TextColor = chartTextColor;
// X Axis
// -- directly get from dataModel.xAxis;
NSObject[] truncatedXAxis = new NSObject[barChartModel.xAxis.Count];
for (int t = 0; t < barChartModel.xAxis.Count; t++) {
if (barChartModel.xAxis [t].Length > 13)
truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t].Substring (0, 11) + "..");
else
truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t]);
}
// Y Axis
BarChartDataSet[] yDataSets = new BarChartDataSet[barChartModel.yAxis.Count];
for (int i = 0; i < barChartModel.yAxis.Count; i++) {
ChartDataEntry[] barEntry = new ChartDataEntry[barChartModel.yAxis [i].Count];
//List<ChartDataEntry> dataEntryList = new List<ChartDataEntry>();
for (int j = 0; j < barChartModel.yAxis [i].Count; j++) {
barEntry[j] = new ChartDataEntry((float)barChartModel.yAxis [i] [j], j);
//dataEntryList.Add(new ChartDataEntry((float)barChartModel.yAxis [i] [j], j));
}
//BarChartDataSet yDataSet = new BarChartDataSet (dataEntryList.ToArray(), barChartModel.dataSetLegend [i].ToString());
// Crashes HERE V
BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i].ToString());
yDataSet.SetColor(chartColors [i]);
yDataSets[i] = yDataSet;
}
// Combine xAxis & yAxis
BarChartData data = new BarChartData (truncatedXAxis, yDataSets);
data.SetValueTextColor (chartTextColor);
data.SetHighlightEnabled (false); // Disable highlight selection
barChartView.SetData(data);
barChartView.SetNoDataTextDescription ("");
barChartView.SetDescriptionText (""); // Disable description - barChartData.SetDescription (String.IsNullOrEmpty (dataModel.name) ? "" : dataModel.name);
barChartView.SetNoDataText (""); // Text displayed when no data is given ("You need to provide data for the chart.");
if (animateChart)
barChartView.AnimateWithYAxisDuration (800);
} catch (Exception ex) {
LogHelper.Debug ("iOSChartHelper", ex.Message, ex);
}
}
The line below this comment // Crashes HERE V is where having crash with below error message throw from binding framework.
fatal error: NSArray element failed to match the Swift Array Element type
Have tried changes the BarchartDataSet to different variable but no luck.
Does anyone have sample code or solution about this issue?
Your barEntry array is a ChartDataEntry array. You should use an Array of BarChartDataEntry
BarChartDataEntry[] barEntry = new BarChartDataEntry[someIntValue];

How to add buttons to a grid WP8.1 MVVM Light?

I'm having trouble building a dashboard in WP8.1.
I'm using the MVVM Light toolkit.
I'm looking after this outcome:
screenshot of dashboard
I can currently build a dashboard but only with one object per row.
I've searched a lot but haven't found anything to get the desired effect.
Here's the code of the dashboard done programatically:
int i = 0;
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
for (int ct = 0; ct < 3; ct++)
grid.ColumnDefinitions.Add(new ColumnDefinition());
StackPanel stackPanel = new StackPanel();
stackPanel.Name = "stackPanel";
stackPanel.Background = new SolidColorBrush(new Windows.UI.Color());
foreach (var flow in dashboard.DashboardFlows)
{
if (flow.Flow.IsInstalled)
{
//if next object should change line
if (i == 3)
{
stackPanel.Children.Add(grid);
grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
for (int ct = 0; ct < 3; ct++)
grid.ColumnDefinitions.Add(new ColumnDefinition());
i = 0;
}
Button button = new Button();
if (flow.Flow.Type.Equals("COMPNEWS"))
{
button.Click += delegate { Frame.Navigate(typeof(NewsPage), flow); };
}
//button stackpanel
StackPanel stack = new StackPanel();
//Button image
Image buttonImage = new Image();
if (!String.IsNullOrEmpty(flow.Flow.IconUrl) || !String.IsNullOrWhiteSpace(flow.Flow.IconUrl))
buttonImage.Source = new BitmapImage(new Uri(flow.Flow.IconUrl));
buttonImage.Height = 45;
buttonImage.VerticalAlignment = VerticalAlignment.Top;
stack.Children.Add(buttonImage);
//Button name
TextBlock buttonName = new TextBlock();
buttonName.Text = flow.Flow.Name;
buttonName.FontSize = 12;
buttonName.TextWrapping = TextWrapping.Wrap;
stack.Children.Add(buttonName);
button.Content = stack;
button.Margin = new Thickness(5, 0, 5, 0);
button.SetValue(Grid.ColumnProperty, i);
button.SetValue(Grid.RowProperty, 0);
button.HorizontalAlignment = HorizontalAlignment.Stretch;
button.VerticalAlignment = VerticalAlignment.Stretch;
button.Background = new SolidColorBrush(Color.FromArgb(130, 30, 30, 30));
grid.Children.Add(button);
i++;
}
}
scroll.Content = stackPanel;
Thank you in advance.

Add Object To Other Object Scripts that require an Object

Ok , I have problem with adding object let's first see what is this about.
I Have Map when i click at map i create Sphere on map.
then i serialized the point, msg and name .....
void Start () {
Ser = new Serial();
Ser.read();
for (int i =0 ; i < Ser.list.Count; i++)
{
Data d = new Data();
d = Ser.list[i];
GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);
a.name = d.Id;
a.transform.position = new Vector3(d.x,d.y,0);
a.transform.localScale =new Vector3(0.5f , 0.5f , 0.5f);
Follow putTarget = new Follow();
Data Pos_In_File = new Data();
Pos_In_File = Ser.list[i];
GUIText GText = new GUIText();
Vector3 SP = new Vector3();
GameObject TextObj = new GameObject("GUIText" + Convert.ToString(i));
GText = (GUIText)TextObj.AddComponent(typeof(GUIText));
GText.text = Pos_In_File.msg;
GText.material.color = new Color(0 , 0 , 1);
GText.fontSize = 20;
GText.fontStyle = FontStyle.Bold;
SP = Camera.main.WorldToViewportPoint(new Vector3(Pos_In_File.x , Pos_In_File.y , Pos_In_File.z));
TextObj.transform.position = SP;
TextObj.AddComponent(typeof(Follow));
GameObject OBJ = GameObject.Find(Pos_In_File.Id);
putTarget =GetComponent<Follow>();
putTarget.target = OBJ.transform;
}
}
now in last three lines i want to add OBJ to TextOBJ->Follow(Script)->target
What i am messing up ?
i asked this quastion long ago my software have been finnished a 10 month
and the i get through this problem is
void Start () {
Resources.UnloadUnusedAssets();
Ser = new Serial();
Screen.fullScreen = true;
Ser.read();
for (int i =0 ; i < Ser.list.Count; i++)
{
Data d = new Data();
d = Ser.list[i];
GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);
a.name = d.Id;
a.transform.position = new Vector3(d.x,d.y,0);
a.renderer.material.color = Color.green;
Data Pos_In_File = new Data();
Pos_In_File = Ser.list[i];
GUIText GText = new GUIText();
Vector3 SP = new Vector3();
GameObject TextObj = new GameObject(Pos_In_File.Id+"h");
GText = (GUIText)TextObj.AddComponent(typeof(GUIText));
GText.text = Pos_In_File.msg;
GText.material.color = new Color(0 , 0 , 1);
GText.fontSize = 20 + (int)Camera.main.transform.position.z;
GText.fontStyle = FontStyle.Bold;
SP = Camera.main.WorldToViewportPoint(new Vector3(Pos_In_File.x , Pos_In_File.y , Pos_In_File.z));
TextObj.transform.position = SP;
TextObj.AddComponent(typeof(Follow));
}

Align itextsharp table

Does anyone know how to left align a iTextSharp table?
You can use the PdfPTable's HorizontalAlignment property.
Here's a C# test method you can use to experiment:
private void TestTableCreation() {
using (FileStream fs = new FileStream("TableTest.pdf", FileMode.Create)) {
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, fs);
doc.Open();
PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 50.0f;
// Options: Element.ALIGN_LEFT (or 0), Element.ALIGN_CENTER (1), Element.ALIGN_RIGHT (2).
table.HorizontalAlignment = Element.ALIGN_LEFT;
for (int i = 1; i <= 20; i++) {
PdfPCell cell = new PdfPCell(new Phrase(String.Format("Cell # {0}", i)));
cell.FixedHeight = 30.0f;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
}
doc.Add(table);
doc.Close();
}
}
table.HorizontalAlignment = 1;
1:center
0:left
2:right
There are two ways of doing it:
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.HorizontalAlignment = 0;