Winforms Linechart - Remove padding - c#

I am currently working on some software and need to generate a Line graph. I've managed to get a linegraph setup just the way I like it, but I cannot seem to find anywhere on how to remove the padding on the left and right of the inner graph. Below is a picture of my graph to help explain what it is I am asking:
As you can see, the first point starts on the second line. What I want to happen is the blue parts of the graph touch both ends (left and right) of the entire chart area. Here is how I plotted my points in C# code:
chart2.Series[0].Points.Clear();
int i = 0;
foreach (var rank in sim.Elements.OrderBy(x => x.Key))
{
chart2.Series[0].Points.AddY((double)rank.Value.TotalPersonel);
chart2.Series[0].Points[i].AxisLabel = Rank.EnlistedRanks[rank.Key];
chart2.Series[0].Points[i].LegendText = Rank.EnlistedRanks[rank.Key];
chart2.Series[0].Points[i].Label = rank.Value.TotalPersonel.ToString();
i++;
}
As you can see in the code snippet, I am clearing any and all points, and starting at an index of 0. I don't understand why the graph starts on the second plot. Does anyone know how to do this? Any help will be much appreciated.

In the chart properties look for ChartAreas collection, select the first and the only item, Axis property's collection, X axis IsMarginVisible = false.

Related

Visual C# creating list of items

I need to make an application that shows codes that update from time to time.
Now I got the back-end part covered but I am completely new to the front end part.
I'd basicly like it took look something like this:
Now the idea is that I'll have a List that holds items that should be converted to elements in the below visual list.. The logo is something I staticly added and that is anchored to the left top corner, I'd like to create the rest of the elemnents dynamically (I have a timed event loop to check if the list has changed, etc)
So I made the following method as a starting point:
private void createOTPEntry()
{
Rectangle entry = new Rectangle();
entry.Name = "entry1";
entry.Stroke = new SolidColorBrush(Color.FromRgb(0, 111, 0));
entry.Fill = new SolidColorBrush(Color.FromRgb(243, 86, 13));
entry.Height = 65;
entry.Width = 497;
Thickness margin = entry.Margin;
margin.Left = 10;
margin.Top = 83;
entry.Margin = margin;
entry.BringIntoView();
}
Now this isn't relative yet to the logo or anything.. But it's supposed to atleast be a white rectangle with an orange border.. And it's not showing. I tried to find if my rectangle object has like a "show" or "draw" method but it doesn't.. And I'm still miles away from what I really want..
So the logic of what I want:
Loop that goes over list elements and draws the visual list elements, probably a Rectangle containing 2 TextBoxes or Labels (one of the labels will change)
These elements will be added to another Container? that has a scrollbar in case there are to many elements.
I'd like some help of possible on what control do I choose to add the elements to? (the container witht he scrollbar?). How exactly do I show my rectangle? Is there an easy way to make them kinda automaticly space when I add them to the "parent control" (the scrollable container).
Thanks in advance for giving me a jump start!

Custom Listbox design

I have a list of dates that I want to present. Initially I thought of using datepicker but it doesn't have max days or max months (Unbelievable) and this is a requirement for me.
Hence I thought of generating my own dates and presenting it to the user.
Below is how I want to display it
I am currently using listbox. I tried combobox, grid view but I am facing the same problem in all of them
Problem
When the date is under the two blue lines I want to set it as selected. The only way I can think of is using code by getting position of the line and then get position of each item in listbox to determine which is falling in the range.
Is there a xaml way to do this?
Any other logic besides determining position? I find this logic extremely crude. A good one would be having a collision box or something which is represented by those lines and when an item hits it, it gets selected
Thanks in advance
So after mucking around for like 3 days I found following solution to be useful
First find the midpoint that is located between the two line. (Find horizontal midpoint, then find vertical midpoint). I found the midpoint using the following code
private void DetermineSelectionLineBoundaries()
{
if (SelectionBoundaryUpper == null || HorizontalScrollPanel == null)
{
return;
}
var transform = SelectionBoundaryUpper.TransformToVisual(Window.Current.Content);
_upperStart = transform.TransformPoint(new Point(0, 0));
_upperEnd = new Point(_upperStart.X + 100, _upperStart.Y);
var lowertransform = SelectionBoundaryLower.TransformToVisual(Window.Current.Content);
_lowerStart = lowertransform.TransformPoint(new Point(0, 0));
var midPointHorizontal = CalculateMidpoint(_upperStart, _upperEnd);
var midPointVertical = CalculateMidpoint(_lowerStart, _upperStart);
_midPoint = new Point(midPointHorizontal.X, midPointVertical.Y);
}
Once you have that, on every scroll call
VisualTreeHelper.FindElementsInHostCoordinates(_midPoint, Window.Current.Content).ToList();
This function will give you all the elements at the point. To be honest I dont just get that element I basically get everything on page that falls vertically on same place as the point. Maybe I am doing something wrong. But the good news is I get only one listbox item. So easy to loop through.
Once that is done, just turn on the IsSelected flag.
Hope this helps someone
I could not find any xaml way to do this.

ASP.NET Chart Manipulation with c#

To explain my question I drew an image, here it is:
So I have a Chart that has a bar graph and a line chart, 2 in 1. I am trying to displaly it in asp.net just the way i drew it on here. This means the A box on the image has a set of values which reflect the line graph, and C box on the image has a set of values that define the bar graph values.
What I want to ask is how do I set two different sets of values on a single chart. I know I can use series to draw multiple graphs and by having series defined as different types I can change if its a bar graph or a ilne chart, however I don't know how to add 2 range of values on the side.
As for the the box B, what I wish to ask is how do I set these values so that they are showing different dates, I was able to do it using a line of code shown bellow, however that line of code sets every value to same, and I need them to reflect different values such as range of dates in this example on the image.
Code that I tried is: Chart1.Series["Series1"].AxisLabel = "Test";
Help is most appreciated!
Cheers!
Ok so i'm going to leave this question up for those that come into similar problem.
This is how you set column A and column c
Chart1.Series[0].YAxisType = AxisType.Primary;
Chart1.Series[1].YAxisType = AxisType.Secondary;
Chart1.ChartAreas[0].AxisY.Maximum = 500;
Chart1.ChartAreas[0].AxisY2.Maximum = 7000;
Your grid lines might get messed up so if you want to disable them use
Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
And just as a bonus if you want to set intervals on each Y axis you can do that with
Chart1.ChartAreas[0].AxisY.Interval = 50;
I still haven't figured out how to do part B that I mentioned, so if you know the answer then please share.
Cheers!

VISIBLOX, WPF: Getting chart points to scroll horizontally?

I'm using the Visiblox WPF API and am having trouble getting the chart points in my line chart to scroll horizontally. Instead of scrolling, the points are get squashed together, in which, this isn't particularly a problem, except that I expect to have 100s of data points on the chart. I have looked throughout the examples available on the Visiblox website, but couldn't find what I was looking for. Ive attached an example screenshot.
Any ideas?
Thanks for your help,
Sparky
By default Visiblox Charts will re-calculate the range to include all the data in the series, so there are two possible approaches: 1) when you add the last point, remove the first one which will effectively move the visible window one point over or 2) set an explicit axis range and update that when you want to move the visible window.
Check out the Visiblox blog for more details on how ranges work at: http://www.visiblox.com/blog/2011/03/visiblox-charts-ranges-demystified
I just had something like this recently. Everytime I'd add a point to the cart I'd run a little section of code that would check the amount of time (my x-axis dimension) that had passed since 0. I also set up a range of data I always wanted to see. I always wanted to show 120 seconds of data on the graph. So I had something like this:
private void adjustXasis(int timeCount)
{
if(timeCount>desiredRange)
{
chart.axis.Xaxis.minimum=timeCount-desiredRange;
chart.axis.Xaxis.maximum=timeCount;
}
else //two minutes not reached yet
{
chart.axis.Xaxis.minimum=0;
chart.axis.Xaxis.maximum=desiredRange;
}
}
I don't have VS in front of me and I know that syntax for the axis min/max is wrong but you get the idea.
By default Visiblox Charts will re-calculate the range to include all the data in the series, so there are two possible approaches:
1) when you add the last point, remove the first one which will effectively move the visible window one point over or
2) set an explicit axis range and update that when you want to move the visible window.
Check out the Visiblox blog for more details on how ranges work at: http://www.visiblox.com/blog/2011/03/visiblox-charts-ranges-demystified

Drawing a map based on an array, and applying run time changes

I am writing a program to control a mobile robot. One of the things it has to do is to draw a map of the "world" as the robot senses it and apply changes in the map as it senses them.
It also has to highlight in some way the location of the robot and (ideally) the direction it points to.
I currently have an auto-updating array (100 x150) representing the map, using the following representations: 0 represents a clear path, 1 represents an obstacle.
I also have a variable containing the robot's location and next location.
What I need is to visualize it. I thought about using labels, but it is way too tedious using them, and the end result is not so pretty. My other possibility is to write all that data into an Excel spreadsheet, but then I will be back to square one: visualizing the data in an attractive way. Is there a drawing package of some sort that can do the job?
To sum it up:
Using:
- int[] MapArray //100 x 150 array representing the robot's world, and the data there is changing.
- Point[] Locations //Locations[0] is the current location, Locations[1] is the next step.
And I want to draw a map on a Windows Forms application that updates itself in a nice visual manner.
I hope my question is clear enough, don't hesitate to contact me if not!
Try Code: Drawing a Filled Rectangle on a Form (Visual C#) or something similar.
Graphics Programming Example Topics
Just write a couple of cycles which accesses every cell of an array and draws a rectangle on a form according to coords - that's the simplest way.
for(int i=0; i<100; i++)
{
for(int j=0;j<150;j++)
{
<access[i,j] and draw a rectangle with color accordingly to your contents.>
}
}
The same for the drawing location.
If you don't find any nice controls, you can always use a DataGridView with the column width = row height so that it always displays square cells. After that, just change the background color of the obstacles.
You could also look into observable collections for the map array so that the grid updates based on events rather than on timers. Make sure that you overwrite the observable collection to send the CollectionChanged event even when a cell changes its value, not only when adding/removing cells.

Categories

Resources