using System.Windows.Forms.DataVisualization.Charting and Custom ScaleView/Zoom - c#

I have a C# application that is using the System.Windows.Forms.DataVisualization.Charting library to display live data input from a test. I need to position the graph so that the x axis spans from 0 to 10, and with the press of a page buttom, it needs to scroll to 5 to 15, 10 to 20, 15 to 25; etc. Setting ScaleView and/or Zoom have done the trick, but when I begin to add data to the graph, it begins resizing automatically. I am able to page through the graph using ScaleView.Position = int NewPosition, however, I need to figure out how to keep the view from autoscaling.
Can this be done?
EDIT:
Found the issue! Turns out ScaleView will zoom just fine as long as you have a Series with points that roughly follow the scale. For example: if you add a line for reference with point 0, 10 and point 10, 10 (or even 5, 10) and your scale is 1, then the graph will autoadjust to fit this larger scale. To fix this, you must put a line with points 0,0 and 0,1 and 0,2 etc, or any other points that are close enough together to ensure the scale stays the way you need it to be.
Hope this clarifies and thanks for anyone who looked.

Related

Formatting numbers on a graph on the horizontal axis in reporting services SSRS

I am working with report services from Visual Studio 2019 and I am making a stacked bar type chart where I need to format the values to percentage, and indeed I have been able to do it but I can not format the horizontal axis, it shows me very large numbers, I have tried in axis properties > axis range and interval, but putting an interval, maximum, etc, has not worked I am already losing my mind, I have searched many sites where the different solutions do not work for me.
I need to show in the horizontal axis values like 0, 20, 40, 60, etc... but as you can see they are too big values, is there any way to format those numbers to show me only the first two digits or something like that? I can not make a division for that because the data is varying, if someone has gone through the same please I need your help, thank you very much.
On the Horizontal Axis properties, you can set the LabelsFormat property in the Property pane or the Custom Format in the Property pop-up to be dynamic based on the values.
=SWITCH(MAX(Fields!DATA.Value) > 1000000, "0,,M;(0,,)M",
MAX(Fields!DATA.Value) > 1000, "0,K;(0,)K",
1 = 1, "0,;(0,)")
This will show values in the millions as 1M, 2M, etc. while thousands would be displayed as 1K, 2K...
The expression ( MAX(Fields!DATA.Value) ) will vary based on the charts' data.

ScottPlot - errorbar with different top and bottom values

This is example for plot with errorbars. But can it be edited so top and values are different? Normally it is for example 20 +- 5, but I want different top and bottom value, so it will be for example 20 + 2, -7.
In case someone still doesn't understand the question, I will provide an example image below.
EDIT: This is now supported natively in ScottPlot 4.1.32: https://scottplot.net/cookbook/4.1/category/plottable-error-bar/#error-bar-quickstart
The old answer is below.
This used to be supported in ScottPlot, but it looks like it was removed in 4.1. Depending on your usecase it may be worth downgrading to 4.0.49, keeping in mind that you will have less features, worse performance, and no updates or support.
You can work around this on 4.1 by using two scatter plots. You draw one scatterplot which is your data. Then you draw another, with markers invisible and symmetrical error bars. You can adjust the y-value of the invisible markers to simulate asymmetrical error bars.
For example, in your example with 20 +2, -7 you would follow these steps:
Plot a marker at y=20
Plot an invisible marker at y=17.5 with visible errorbars of ± 4.5

How to fill part of the graphical figure

So, I have some simple figure (circle, ellipse, rectangle of closed polygon) and I need to fill only part of it.
I mean, I have GraphicsPath or similar object (set of points) and now I can simply fill the whole figure with, for example, orange color.
What I need: user enters 25% and I fill only 25% of the figure, starting from some side (top/bottom).
Maybe, it will be nessesary to find some sub-figure or (bad idea, I know) check all the points in on the field and fill them (only those which inside figure) one by one untill their amount will be 1/4 from the area of the figure. But it won't be so fast especially when image is about 5-6000 pixels from one side.
Here's sample what I have now and what I need for 25%. Important: instead of 25% can be any value.
Project: C# .net 3.5 WinForms
UPD:
Basic usecase.
User draws a figure (circle, ellipse, rectangle, polygon)
User enters value from 0 to 100 (percents)
I fill figure from bottom to the top until I filled amount of area (!), which is equal to user's value
I'm open for any ideas even without code.

How to change drawing line size in TeeChart

I am working with TeeChart fro .net, I would like to increase the size of drawing line in the chart. presently it is drawing very thin line which is not visible for all people. How to increase size of drawing line in TeeChart.
I have attached a simple chart image from my application. I would like to draw the line with more or equal size to axis lines. presently it seems drawing line size less that axis line size. I mean i want to draw line more thick.
2) How to assign axis scale more reliably, i mean presently if i have axis minimum and maximum values from 0 to 6, then it is showing on the axis like 0,2,4,6. I would like to see like 0,1,2,3,4,5,6 like that i mean with 1 scale increment. Please help me with the above two things.
1) How to increase drawing line size?
2) How to assign scale of axis more convenient?
The chart's features mention support for Csharp .NET charting control.
http://www.steema.com/teechart/net
Microsoft has pages with information about the chart controls:
http://msdn.microsoft.com/en-us/library/dd456632.aspx
Looks like you will find how to do the things you want there.
1) How to increase drawing line size?
You can set Line or FastLine Pen.Width like this:
line1.LinePen.Width = tChart1.Axes.Left.AxisPen.Width;
2) How to assign scale of axis more convenient?
TeeChart will automatically set axis scales to the minimum increment possible provided labels don't overlap. To get a fixed axis increment you should set axis Increment property. Labels won't be allowed to overlap though.
tChart1.Axes.Bottom.Increment = 1;
For more information on axis settings please read tutorial 4. Tutorials can be found at TeeChart's program group.

Snake in C# - player can scale window - dividing manual-scaled window into identical squares

As part of my self-education of programming I decided to make a snake in C#. The problem I have is about the client size of the game form.
I want player to be able to scale the window of the game, which is divided into 25 x 25 grid (every coordinate is like "one pixel") - it means, that at any moment, the window is divided into 25 x 25 identical squares.
The problem I get is near this code:
int SquareSide = (ClientSize.Width / 25);
When I set the ClientSize strictly to for example 600 x 600, which is a multiple of 25, everything goes OK. But when I don't (for example by manual resizing, which can change the size to, for example, 711 x 711), it creates at the right side a 'strip', which seems to be the rest of pixels, which can't be used because we are dividing to integer number.
My question is - is there any not-extremely-hard way to achieve dividing ANY client size of form into 25 x 25 grid without this problem? I tried using double, but FillRectangle method doesn't accept it.
I hope my question is understandable and thank you for replies.
To tell you the truth, there is
g.FillRectangle(Brush b, RectangleF rect)
RectangleF is a rectangle whose coordinates are float.
So you can use:
float SquareSide = (ClientSize.Width * 1f / 25);
I would try to simply handle OnResize event of the window, and at the moment user finishes rezise it, force the size that program need for perfect fit of the grid.
So for example at the moment user releases mouse and you figure out that one dimensions of the window 711x711, bring it to nearest correct fit 700x700.
In this way you guarantee good user experience on different monitor resolutions and for you guarantee a correct fit of the grid you draw.
Hope this helps.
Switch to float coordinates for everything. Make sure your game looks OK when lines do not have whole pixel coordinates. Make sure you "find next cell" code also works with floats, including mouse position detection if needed.
The other approach is to be happy with integer coordinates (and cells of the same size) and make page layout flexible to accomodate some unused space for odd 711x711 layouts (i.e. just center the field and keep some variable width border).

Categories