I have made a chart with rmchart and i was wondering if it is possible to automatically resize the chart when i resize the form where it's in.
Printable View
I have made a chart with rmchart and i was wondering if it is possible to automatically resize the chart when i resize the form where it's in.
Ive never used rmchart but you should be able to set its size and location properties.
Code:Option Explicit
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
RMChart1.Left = 0
RMChart1.Top = 0
RMChart1.Width = Me.ScaleWidth
RMChart1.Height = Me.ScaleHeight
End If
End Sub
This doesn't seem to work. :(
Well since I dont have the control you need to tell us if it has those properties or not?
It's a special kind of chart where you need a rmchart.dll file. You can find information on it at www.rmchart.com
The properties that this chart has is nog clear to me.
This works for me.
vb Code:
Dim x As Single Dim y As Single Private Sub Form_Load() x = RMChartX1.Height / Me.ScaleHeight y = RMChartX1.Width / Me.ScaleWidth End Sub Private Sub Form_Resize() RMChartX1.Height = Me.ScaleHeight * x RMChartX1.Width = Me.ScaleWidth * y End Sub
Properties are a basic "thing" of programming. You really should check out a book on VB 6 then to help get you up to speed on the basics. ;)
A property is just like in languages you speak, adjectives describe a noun. A Property describes an object.
.Width, .Height, .Top and .Left are all describing your chart object and are all properties.
This will probably work if you have created a chart with the rmchart.dll. But if you have created it with the rmcdesigner this doesn't seem to work.Quote:
Originally Posted by lintz
Here is the code that this program has created:
Maybe you can see how you can resize this chart.Code:Sub DoTheChart()
Dim i As Long
Dim nC As Long
Dim nDataCount As Long
Dim nDataXCount As Long
Dim nDataYCount As Long
Dim nRetVal As Long
Dim sTemp As String
ReDim aData(0) As Double
ReDim aData2(0) As Double
ReDim aPPC(0) As Long
ReDim aColor(0) As Long
Dim tChart As tRMC_CHART
Dim tRegion As tRMC_REGION
Dim tCaption As tRMC_CAPTION
Dim tLegend As tRMC_LEGEND
Dim tGrid As tRMC_GRID
Dim tDataAxis As tRMC_DATAAXIS
Dim tLabelAxis As tRMC_LABELAXIS
Dim tBarSeries As tRMC_BARSERIES
Dim tLineSeries As tRMC_LINESERIES
Dim tGridlessSeries As tRMC_GRIDLESSSERIES
Dim tXYAxis As tRMC_XYAXIS
Dim tXYSeries As tRMC_XYSERIES
'************** Create the chart **********************
tChart.nLeft = 10
tChart.nTop = 90
tChart.nWidth = 900
tChart.nHeight = 700
tChart.nBackColor = Transparent
tChart.nCtrlStyle = RMC_CTRLSTYLEFLAT
tChart.sBgImage = ""
tChart.sFontName = "Tahoma"
tChart.nToolTipWidth = 0
tChart.nBitmapBKColor = Default
nRetVal = RMC_CreateChartOnDCI(Me.hDC, ID_RMC1, tChart)
If nRetVal < 0 Then GoTo IsError
'************** Add Region 1 *****************************
tRegion.nLeft = 10
tRegion.nTop = 10
tRegion.nWidth = -5
tRegion.nHeight = -5
tRegion.sFooter = ""
tRegion.nShowBorder = False
nRetVal = RMC_AddRegionI(ID_RMC1, tRegion)
If nRetVal < 0 Then GoTo IsError
'************** Add caption to region 1 *******************
tCaption.sText = "Modus Svs"
tCaption.nBackColor = Default
tCaption.nTextColor = Default
tCaption.nFontSize = 10
tCaption.nIsBold = False
nRetVal = RMC_AddCaptionI(ID_RMC1, 1, tCaption)
If nRetVal < 0 Then GoTo IsError
'************** Add grid to region 1 *****************************
tGrid.nGridBackColor = Default
tGrid.nAsGradient = True
tGrid.nBiColor = RMC_BICOLOR_NONE
tGrid.nLeft = 0
tGrid.nTop = 0
tGrid.nWidth = 0
tGrid.nHeight = 0
nRetVal = RMC_AddGridI(ID_RMC1, 1, tGrid)
If nRetVal < 0 Then GoTo IsError
'************** Add first X axis to region 1 *****************************
tXYAxis.nAlignment = RMC_XAXISBOTTOM
tXYAxis.nMinValue = 0
tXYAxis.nMaxValue = 400
tXYAxis.nTickCount = 9
tXYAxis.nFontSize = 8
tXYAxis.nTextColor = Default
tXYAxis.nLineColor = Gray
tXYAxis.nLinestyle = RMC_LINESTYLEDASH
tXYAxis.nDecimalDigits = 0
tXYAxis.sUnit = ""
tXYAxis.sText = "Diepte [m]"
tXYAxis.sLabels = ""
nRetVal = RMC_AddXAxisI(ID_RMC1, 1, tXYAxis)
If nRetVal < 0 Then GoTo IsError
'************** Add first Y axis to region 1 *****************************
tXYAxis.nAlignment = RMC_YAXISLEFT
tXYAxis.nMinValue = Menu.Yas1
tXYAxis.nMaxValue = Menu.Yas2
tXYAxis.nTickCount = 11
tXYAxis.nFontSize = 8
tXYAxis.nTextColor = Default
tXYAxis.nLineColor = Gray
tXYAxis.nLinestyle = RMC_LINESTYLEDASH
tXYAxis.nDecimalDigits = 0
tXYAxis.sUnit = ""
tXYAxis.sText = "Geluidssnelheid [m/s]"
tXYAxis.sLabels = ""
nRetVal = RMC_AddYAxisI(ID_RMC1, 1, tXYAxis)
If nRetVal < 0 Then GoTo IsError
'************** Add Series 1 to region 1 *******************************
tXYSeries.nColor = Navy
tXYSeries.nStyle = RMC_XY_LINE
tXYSeries.nLinestyle = RMC_LSTYLE_LINE
tXYSeries.nSeriesSymbol = RMC_SYMBOL_NONE
tXYSeries.nWhichXAxis = RMC_XAXISBOTTOM
tXYSeries.nWhichYAxis = RMC_YAXISLEFT
tXYSeries.nValueLabelOn = RMC_VLABEL_NONE
nRetVal = RMC_AddXYSeriesI(ID_RMC1, 1, aData(0), 0, aData2(0), 0, tXYSeries)
If nRetVal < 0 Then GoTo IsError
'****** Set name and parameters for the X-datafile for series 1 ******
nRetVal = RMC_SetSeriesDataFile(ID_RMC1, 1, 1, "C:\modus svs\Testfile modus svs.csv", "1,1500", "2", ";", False)
If nRetVal < 0 Then GoTo IsError
'****** Set name and parameters for the Y-datafile for series 1 ******
nRetVal = RMC_SetSeriesDataFile(ID_RMC1, 1, 1, "C:\modus svs\Testfile modus svs.csv", "1,1500", "1", ";", True)
If nRetVal < 0 Then GoTo IsError
nRetVal = RMC_SetWatermark(RMC_USERWM, RMC_USERWMCOLOR, RMC_USERWMLUCENT, RMC_USERWMALIGN, RMC_USERFONTSIZE)
nRetVal = RMC_Draw(ID_RMC1)
If nRetVal < 0 Then GoTo IsError
Exit Sub
IsError:
End Sub
This seems to work.
In the chart i have used this code:Code:Private Sub Form_Resize()
Chart.Cls
DoTheChart
This will only make de program a bit slow.Code:
tChart.nWidth = Chart.ScaleWidth-50
tChart.nHeight = form.ScaleHeight - 100
Where do you have the .nWidth and .nHeight code? In the Form_Resize? If so and its still slow then its the limitation of the chart control you are using.
That code i have put in the procedure dothechart.
What makes it slow is that with every resize i do with the form it has to clear the form and rebuild the chart. I hope there is a better way, but it does work.:o
Well the resize event is the correct place to set the size of the chart but if the chart control requires you to rebuild the entire thing to resize the chart then thats not good at all. Maybe you would want to use a better cahrt control.
Did you read any of the documentation that is for the chart control?
There isn't any information about the chart controle for the chart that is created in rmcdesigner. If i want to use the chart controle of rmchart i have to build a whole new chart by hand and i don't know how to do that yet.:(
Doesnt the MSChart control in the vb 6 toolbox work well enough? Its alot easier to use but may not have alot of fancy chart designs.
You don't need to keep creating the chart each time you resize the form. If you simply resize the chart (width and height) when the form is resized everything will be OK :thumb:
Thats what I thought and mentioned it in post #2 but he says it doesnt work. :confused:
This may work for the mschart, but this doesn't work with a chart created with rcmdesigner.Quote:
Originally Posted by lintz
I will try to create the chart with mschart then. First have to find out how this works.:confused:
Can someone tell me where to find a good tutorial on creating a chart with mschart on the internet?:confused:
I want to create a chart with mschart and the data he has to get form a text file, can someone help me on how to start?
Well first of all add it to your toolbox and drop it on to a form.
Resizing it is a single line of code.
Code:Option Explicit
Private Sub Form_Resize()
MSChart1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Oke that is if you have a chart created with mschart. I have created it with RMchart. Now i have to find out how to create a mschart.
Yes, but didnt you try it? Drop a chart control on to your form and add the posted code. Now it will resize easily and the rest is just populating its properties and so fourth to suit your needs.
No i didn't try it because i don't know how to create one yet.
Give this a shot. Add a instance of the RMChart control and Command Button.
vb Code:
Option Explicit Dim x As Single Dim y As Single Private Sub Form_Load() x = RMChartX1.Height / Me.ScaleHeight y = RMChartX1.Width / Me.ScaleWidth End Sub Private Sub Form_Resize() RMChartX1.Height = Me.ScaleHeight * x RMChartX1.Width = Me.ScaleWidth * y End Sub Private Sub Command1_Click() ' Single bars Dim nRetval As Long Dim sTemp As String With RMChartX1 '************** Design the chart ********************** .Font = "Comic Sans MS" .RMCBackColor = AliceBlue .RMCStyle = RMC_CTRLSTYLEFLAT '************** Add Region 1 ***************************** .AddRegion With .Region(1) .Left = 5 .Top = 5 .Width = -5 .Height = -5 .Footer = "" '************** Add caption to region 1 ******************* .AddCaption With .Caption .Titel = "This is the chart's caption" .BackColor = Blue .TextColor = Yellow .FontSize = 11 .Bold = True End With 'Caption '************** Add grid to region 1 ***************************** .AddGrid With .Grid .BackColor = Beige .AsGradient = False .BicolorMode = RMC_BICOLOR_LABELAXIS .Left = 0 .Top = 0 .Width = 0 .Height = 0 End With 'Grid '************** Add data axis to region 1 ***************************** .AddDataAxis With .DataAxis(1) .Alignment = RMC_DATAAXISLEFT .MinValue = 0 .MaxValue = 100 .TickCount = 11 .FontSize = 8 .TextColor = Black .LineColor = Black .LineStyle = RMC_LINESTYLEDOT .DecimalDigits = 0 .AxisUnit = "" .AxisText = "" End With 'DataAxis(1) '************** Add label axis to region 1 ***************************** .AddLabelAxis With .LabelAxis .AxisCount = 1 .TickCount = 5 .Alignment = RMC_LABELAXISBOTTOM .FontSize = 8 .TextColor = Black .TextAlignment = RMC_TEXTCENTER .LineColor = Black .LineStyle = RMC_LINESTYLENONE sTemp = "Label 1*Label 2*Label 3*Label 4*Label 5" .LabelString = sTemp End With 'LabelAxis '************** Add Series 1 to region 1 ******************************* .AddBarSeries With .BarSeries(1) .SeriesType = RMC_BARSINGLE .SeriesStyle = RMC_BAR_FLAT_GRADIENT2 .Lucent = False .Color = CornflowerBlue .Horizontal = False .WhichDataAxis = 1 .ValueLabelOn = False .PointsPerColumn = 1 .HatchMode = RMC_HATCHBRUSH_OFF '****** Set data values ****** sTemp = "50*70*40*60*30" .DataString = sTemp .SetColorValue 3, Red ' Set the color for the third bar to Red End With 'BarSeries(1) End With 'Region(1) nRetval = .Draw End With 'RMChartX1 End Sub
When i resize my form the chart doesn't change. Can you explain how i can use data from a textfile for my chart?
I dont think his resize code is correct.
Try my resize code from post #20
Lintz is using rmchart and you're code is for mschart.
Is there no guide on the internet which can help me to create a chart from data in a text file?
Oh I thought you had switched as you were requesting info on the control (post #19).
Well decide which control you are going to use and goole it for tutorials. RMChart should have at least something on their site for support. Have you even looked there yet?
If your 'C:\Program Files\RMChart\VB6_DLL' folder open the project 'rmchartdemo.vbp' which will show a lot of examples including how to read data from a csv file.Quote:
Originally Posted by xavier73
With the rmcdesigner it is easy to get the data from a text file for a chart. When i want to use the rmchart.dll and make the chart manually i can't find now information about that on the website of rmchart and on the internet. So i will use the chart i have created with the rmcdesigner. This works fine for now.
Please mark thread as closed if your issue is resolved :thumb: