Gridlines showing on my teechart graph in .net - vb.net

So I have a TeeChart graph in VB.net winForms.
It has a few logarithmic gridlines on it.
However, when I add labels, I get extra gridlines too. I never wanted these there, and I'm wondering if anyone's got ideas on how to get rid of them.
This is the code I ran:
tcRPP.Axes.Bottom.Labels.Items.Clear()
tcRPP.Axes.Bottom.Labels.Items.Add(xMin / 2.3D, "Points in bucket:")
For Each group In xGrouped
tcRPP.Axes.Bottom.Labels.Items.Add(group.Average(Function(point) point.X), CStr(group.Count()))
Next
My graph now looks like this:
Any help would be much appreciated!

In the end I hid the graph altogether by saying:
Dim pointSeries As Series = chartseriesAsList().FirstOrDefault(Function(x) x.GetType() = GetType(Points3D))
Dim xAxis = pointSeries.GetHorizAxis
xAxis.Grid.Visible = false
Dim yAxis = pointSeries.GetVertAxis
yAxis.Grid.Visible = false

Related

Is there an alternative to View.GetOutline() which gives a better outline?

Outline returned by View.GetOutline() method does not quite correspond to the visible drawing - it returns a bit more than the selection outline shown by SolidWorks GUI.
The screenshot below shows the selection outline (light blue dotted rectangle) and diagonal of the outline returned by View.GetOutline() (red line):
Is there a way to get bounding box that corresponds to the actually visible drawing?
Note: Original title of this question was "Is there an alternative to View.GetOutline() which does NOT include Temporary Axes?", however I discovered that View.GetOutline() actually does not include Temporary Axes. The problem was in the View.Position property which defines center bounding box that includes Temporary Axes.
Artem's answer was quite useful so I decided to change the question to correspond to the answer and post a new question for the actual problem.
You can get the bounding box from underlying model via IPartDoc::GetBox/IAssemblyDoc::GetBox API and transform this to a view space via IView::ModelToViewTransform as shown in this example.
You will only need the following portion of code form the DrawBBoxDiagonal function if you do not want to draw the diagonal. The values of vStartPt and vEndPt are the end points of bounding box.
Dim vBox As Variant
Dim swViewTransform As SldWorks.MathTransform
Dim swMathPt As SldWorks.MathPoint
Dim vStartPt As Variant
Dim vEndPt As Variant
vBox = GetViewRefModelBBox(view)
Set swViewTransform = GetViewToSheetTransform(draw, view)
Dim swMathUtils As SldWorks.MathUtility
Set swMathUtils = swApp.GetMathUtility
Dim dPt(2) As Double
dPt(0) = vBox(0): dPt(1) = vBox(1): dPt(2) = vBox(2)
Set swMathPt = swMathUtils.CreatePoint(dPt)
Set swMathPt = swMathPt.MultiplyTransform(swViewTransform)
vStartPt = swMathPt.ArrayData
dPt(0) = vBox(3): dPt(1) = vBox(4): dPt(2) = vBox(5)
Set swMathPt = swMathUtils.CreatePoint(dPt)
Set swMathPt = swMathPt.MultiplyTransform(swViewTransform)
vEndPt = swMathPt.ArrayData
I would also recommend to get precise bounding box via IBody2::GetExtremePoint as shown here

Saving chart in userform as picture

A part of this question concerns doing the reverse of the following one:
VB.net get location of userControl in another container
No matter what I do, I cannot seem to pinpoint the location of my chart inside a userform (D inside A), therefore what I save is something very different than the chart alone.
So, provided that my userform is too like this:
I need to save a screenshot of D, being D a polar chart with a title and a legend.
My code is:
Dim PicFile As String = FilesFolder & "Pic.png"
Dim myBounds As Rectangle = A.D.Bounds
Dim BitMap As New Bitmap(myBounds.Width, myBounds.Height)
Dim PtChart As Point
PtChart = A.PointToScreen(New Point(0, 0))
PtChart = A.D.PointToClient(PtChart)
Using g As Graphics = Graphics.FromImage(BitMap)
g.CopyFromScreen(PtChart, Point.Empty, myBounds.Size)
End Using
BitMap.Save(PicFile, System.Drawing.Imaging.ImageFormat.Png)
Why does this not save the chart (D) correctly?
BONUS: how can I make it work even when I have another application open (say, internet browser) on top of the userform?

DevExpress SpreadSheetControl Chart set line color /style

DevExpress website is unable to tell me. How can I influence the line color, thickness, etc. of created graphs?
Dim chart As Chart = myworb.Worksheets(1).Charts.Add(Charts.ChartType.ScatterLine)
chart.TopLeftCell = myworb.Worksheets(1).Cells("A83")
chart.BottomRightCell = myworb.Worksheets(1).Cells("F112")
chart.PlotArea.Fill.SetNoFill()
chart.Series.Add(myworb.Worksheets(1)("A1:A71"), myworb.Worksheets(1)("B1:B71"))
chart.Series.Add(myworb.Worksheets(1)("D1:D81"), myworb.Worksheets(1)("E1:E81"))
chart.Series.Add(myworb.Worksheets(1)("G1:G81"), myworb.Worksheets(1)("H1:H81"))
chart.Series.Add(myworb.Worksheets(1)("J1:J71"), myworb.Worksheets(1)("K1:K71"))
chart.Series.Add(myworb.Worksheets(1)("M1:M66"), myworb.Worksheets(1)("N1:N66"))
chart.Title.Visible = False
Dim axisX = chart.PrimaryAxes(0)
axisX.MajorTickMarks = AxisTickMarks.None
axisX.Scaling.AutoMax = False
axisX.Scaling.AutoMin = False
axisX.Scaling.Max = maxX1
axisX.Scaling.Min = minX1
Dim axisY = chart.PrimaryAxes(1)
axisY.MajorTickMarks = AxisTickMarks.None
axisY.Scaling.AutoMax = False
axisY.Scaling.AutoMin = False
axisY.Scaling.Max = maxY1
axisY.Scaling.Min = minY1
Normally I would just create an Excelfile as a template, load it into the control an just fill the values the chart is using as a series. But as I have to scale it manually because Excel autoscale is NOT WORKING, I have to create the whole chart from scratch. I am unable to find information about how I can set colors etc in the chart programatically. Any help is greatly apreciated.
You can set the color and thickness by using ShapeFormat.Outline property of your series objects. Call to ShapeOutlineFill.SetSolidFill method to set the color of your line and use the ShapeOutline.Width property to set the line width.
Here is example:
chart.Series(5).Outline.SetSolidFill(Color.Magenta)
chart.Series(5).Outline.Width = 20
The "lines" are the chart series and can be accessed in the Series property. From there you can change various things about the series including the color. Alternatively you can custom draw series yourself using the CustomDrawSeries event.

Microsoft.Office.Interop.Excel Line Chart Color And Bar Chart Color Alpha

I am using the following code to format properties of a chart created by Microsoft.Office.Interop.Excel.
xlChart.SeriesCollection(1).ChartType = XlChartType.xlColumnClustered
xlChart.SeriesCollection(2).ChartType = XlChartType.xlLine
xlChart.SeriesCollection(1).Interior.Color = Color.FromArgb(255, Color.DeepSkyBlue)
xlChart.SeriesCollection(2).Interior.Color = Color.FromArgb(255, Color.DarkOrange)
I have two problems. For the xlColumnClustered chart, the color is fine but the Alpha value does not have any affect (whether being 0 or 126 or 255). For the xlLine even the color doesn't get set. I know probably for xlLine I shouldn't use .Interior.Color but I don't know what I am supposed to use. Any help will be appreciated.
I don't think you can use a transparent color directly. What you can do is set the transparency parameter of the series like this:
Chart.SeriesCollection(1).Format.Fill.Transparency = 0.5
For line you should use:
Chart.SeriesCollection(1).Format.Line.Forecolor.RGB = RGB(255, 0, 0)
I wrote a blog post about how to find out which objects and properties should you use to achieve your result. It seems it might help you find with other difficulties in locating the right objects to use-

Scaling form controls according to screen resolution

I am trying to write program in vb 2010 that is independent of screen resolution.
I am designing the program in 1920*1080 and when I change the resolution to e.g. 800*600 everything blows up and the program won't fit the screen. How can I fix this?
I have tried three different approaches:
loop through all controls and scale their position and dimensions
Friend Sub ResizeControl(ByRef ctl As Control)
'---------------------------- GET SCALES -------------------------
Dim DesignScreenWidth As Integer = 1920
Dim DesignScreenHeight As Integer = 1080
Dim CurrentScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
Dim CurrentScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
'Ratios
Dim ratioX As Double = CurrentScreenWidth / DesignScreenWidth ' e.g. 800/1920
Dim ratioY As Double = CurrentScreenHeight / DesignScreenHeight
With ctl
Dim height As Integer = Math.Min(.Height, CurrentScreenHeight)
Dim width As Integer = Math.Min(.Width, CurrentScreenWidth)
'Position
If (.GetType.GetProperty("Top").CanRead) Then .Top = CInt(.Top * ratioY)
If (.GetType.GetProperty("Left").CanRead) Then .Left = CInt(.Left * ratioX)
'Size
If (.GetType.GetProperty("Width").CanRead) Then .Width = CInt(width * ratioX)
If (.GetType.GetProperty("Height").CanRead) Then .Height = CInt(height * ratioY)
End With
'---------------------- RESIZE SUB CONTROLS -------------------------------
For Each subCtl As Control In ctl.Controls
ResizeControl(subCtl)
Next subCtl
End Sub
Anchor each control to the main Form and only resize the main form
tried to AutoScale Mode
Dim factorX As Double = ratioX * 96.0F
Dim factorY As Double = ratioY * 96.0F
Dim newSize As SizeF = New SizeF(factorX, factorY)
AutoScaleDimensions = newSize
AutoScaleMode = AutoScaleMode.Dpi
Scale(newSize)
Font = New Font(Font.FontFamily, Font.Size * factorX)
None of these methods has worked for me. What am I doing wrong?
One thing I figured out was that my main form is larger than 800*600 pixels so when I run the designer in 800*600 resolution VS cut down the with to 812px so my calculations of with and thus scaling ratio becomes wrong. This error goes applies for all three methods.
Please advise on the best method and if I am doing something wrong.
As an expansion to my first comment, take a look at some best practices from the UX (user experience) world. There is a lot of science and and deliberation put into UIs that work.
There's a great SE site - ux.stackexchange.com that you may find can answer your questsions better than SO.
Here's some questions you may find helpful:
https://ux.stackexchange.com/questions/3414/desktop-software-design-patterns (see MS & Apple have their own guidelines incl. things like button widths)
https://ux.stackexchange.com/questions/11361/responsive-web-design-technique-in-desktop-application
Responsive web design seems to parallel what you're doing. The idea behind it is to have your website be able to handle any client device - which is becoming very important because of the mobile explosion.
I suggest doing some studying in these areas to come up with a good solution.