DevExpress SpreadSheetControl Chart set line color /style - vb.net

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.

Related

How to maintain the size of fonts in anchored MSGraph Chart object

I have a anchored MSGraph Chart object on my form to stretch left and bottom. It stretches well but the fonts also stretch. How do I maintain the same font size for all the Data labels but still be able to view the graph in full size on stretched or zoomed mode? My aim is to keep font sizes for all Data labels and Axis to 11pt. The original font size for the Data Labels and Axis is 8pt
Edit:
I have notice that when I select the Zoom or Stretch features in the Chart's properties sheet, the chart stretches and the so does the fonts. This does not happen if I select Clip
Is it possible to make the chart stretch whilst maintaining the font sizes to 11pt? I am asking this because when I looked at the chart on a 4:3 screen today, some fonts were barely visible. Please see the image of my current graph and together with its properties settings below:
I have inserted a Stacked Layout with two cells onto the the form, then inserted the chart object in the first cell and left the second cell empty.
A good thing is that an empty cell can be anchored to Strech when the form resizes to suit the screen's aspect ratio.
I then adjusted the height of the blank cell and anchored both the object and the blank cell to Sctrech Down and Across.
On the chart properties, the chart Size Mode must be set to Strecth
Then used the below code on the form open event:
Note: This code requires the use of Microsoft Graph Object Library which should be added using the Tools -> References feature on the code editor.
I am using Microsoft Graph 16.0 Object Library.
I shall be exploring how to use latebinding inorder to avoid this step or perhalps somone can comment.
Dim myChart As Graph.Chart
Dim myChartSeries As Graph.Series
Dim mySeriesDataLabel As Graph.DataLabel
Set myChart = Me.myGraph.Object
For Each myChartSeries In myChart.SeriesCollection
For Each mySeriesDataLabel In myChartSeries.DataLabels
mySeriesDataLabel.Font.Name = "Times New Roman"
mySeriesDataLabel.Font.FontStyle = "Normal"
mySeriesDataLabel.Font.Size = 8
Next mySeriesDataLabel
Next myChartSeries
With Me.myGraph.Axes(1).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
With Me.myGraph.Axes(2).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
Without Anchoring:
After Anchoring:

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

Gridlines showing on my teechart graph in .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

Word VSTO - Change the absolute positions' type?

I use the following VB.NET (VSTO) code to add a shape in MS-Word,
Dim app As Word.Application = Globals.ThisAddIn.Application
Dim doc As Word.Document = app.ActiveDocument
Dim left As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdHorizontalPositionRelativeToPage)))
Dim top As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)))
Dim shape As Word.Shape = doc.Shapes.AddShape(1, left, top, 225.1F, 224.5F)
shape.Fill.BackColor.RGB = ColorTranslator.ToOle(Color.Transparent)
shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
shape.Fill.Transparency = 0.0F
shape.Line.Transparency = 0.0F
shape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
What this code does is, it adds a rectangle shape at cursor point and makes it transparent (both background and line).
Now I like to change the absolute positions' type. To explain further, when you select the rectangle shape, then if you select the Ribbon tab Format > Position > More Layout Options... as shown in the image below,
It will open the following dialog,
In the above dialog I like to change Column and Paragraph marked by the red rectangles into the type Margin. How to do this by code?
Word provides a Macro recorder. You may use it to get the code generated for you in the background. Thus, you will find what properties and methods exactly should be used to get the job done. See Record or run a macro for more information.
The solution to this was solved in the link below,
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e69584d7-24fe-4396-9a82-26b7dae02584/word-vsto-change-the-absolute-positions-type?forum=vsto

Gantt chart in vb.net windows application

I am looking for developing Gantt chart application in vb.net windows application.
I wants to know is there any free third party tool or some demo application so that I can learn about it.
You can use System.Windows.Forms.DataVisualization.Charting to do so. Here is some sample code.
Dim newSeries As New Series
openConn()'opens the connection
openRS("SELECT * FROM Data")'pull data from database
Do Until rs.EOF
newSeries = New Series'create a new dataSeries
yPlot1 = CDbl(rs.Fields("Start Date").Value.ToOADate())'set beginning of bar
yPlot2 = CDbl(DateAdd(DateInterval.Day, rs.Fields("Duration").Value, rs.Fields("Start Date").Value).ToOADate())'set end of bar
newSeries.ChartType = SeriesChartType.RangeBar
newSeries.YValuesPerPoint = 2
newSeries.CustomProperties = "DrawSideBySide=false"
xOrdinal = rs.Fields("Ordinal").Value
newSeries.Points.AddXY(xOrdinal, yPlot1, yPlot2)
newSeries.Points(0).ToolTip = rs.Fields("Task Name").Value.ToString
newSeries.Name = rs.Fields("Task Name").Value.ToString
newSeries.Points(0).Color = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(rs.Fields("Color").Value.ToString)), KnownColor))
newSeries.Points(0).AxisLabel = rs.Fields("Ordinal Name").Value.ToString
seriesList.Add(newSeries)
rs.MoveNext()
Loop
rs = Nothing
cn.Close()
cn = Nothing
Chart1.Series.Clear()
For Each plotSeries As Series In seriesList
Chart1.Series.Add(plotSeries)
Next
Chart1.ChartAreas(0).AxisX.Interval = 1
Chart1.ChartAreas(0).AxisY.Interval = 7
Chart1.ChartAreas(0).AxisX.IsReversed = True
Chart1.ChartAreas(0).AxisY.IsStartedFromZero = False
Chart1.ChartAreas(0).AxisY.IsMarginVisible = False
Chart1.ChartAreas(0).AxisY.IntervalType = DateTimeIntervalType.Days
Chart1.ChartAreas(0).AxisY.Minimum = CDbl(#4/1/2012#.ToOADate())
Chart1.ChartAreas(0).AxisY.Maximum = CDbl(#6/30/2012#.ToOADate())
Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "ddd M/d"
Chart1.Update()
You will need a Chart control on your form (Chart1). And of course, your data may be different, but this may give you the step you are missing. You can also check out the following document for further details.
http://wiki.visualwebgui.com/pages/images/6/6a/MSChartsGanttChartAndPrinting.pdf
You can easily draw GANTT chart using GDI API in VB.NET. Take a look at codeproject article.