Ace Master Posted November 26, 2003 Posted November 26, 2003 hi. I have this chart and by default , the max value is 100. The problem is that my values are between 0 and 10...or 20 ...etc.. How I can make dinamicaly rescale the max chart value? I tried some tricks but when I write my code the chart is not visible. thanks. Quote
AlexCode Posted November 26, 2003 Posted November 26, 2003 I'm sorry but you'll have to explain yourself a little better... What kind chart do u have? What is the logic? I'll be wayting... :D Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
Ace Master Posted November 26, 2003 Author Posted November 26, 2003 Hi Alex. I have a chart control in vb.net In this chart I will put different kind of values. They are not between 0 and 100. I can have 100 but in the most cases they are small values. I can have also values like 0.2858 or 1.547. If I have the chart with 100 scale, my small value (0.2545) will be to small for showing in my chart. So¡K I will make a maximum and minimum from my values and I want to set the max chart scale by this value. Ex: The last 6 values are : 0.2, 2.3, 0.2568, 0.987, 1.4558, 2.488, 5.4888 In this case I want the max scale value for the chart to be 6. If I want to display the last month values, maybe I will have there a value eq to 50. In this case the chart will show the max 50 on the scale. You understand what I want? I need only the code for modifies the chart max scale. After that I have programming knowledge to build my function. I think :) Thanks a lot Quote
AlexCode Posted November 26, 2003 Posted November 26, 2003 Is this the same chart component I helped you some time ago? :D Try this code... I tryed to coment it the best as possible... Any doubts just ask ok? '-| INFO |--------------------------------------------------------------- 'THIS IS A CLASS THAT CALCULATES A SCALE BASED ON THE VALUES THAT ARE 'SUPPOSED TO BE DISPLAYED... ' 'THE VALUES IS ENTERED ON THE 'SUB NEW' AS AN ARRAYLIST AND USING THE ''GetScaleValues' METHOD WE CAN RETRIEVE THE SCALE ALSO ON AN ARRAYLIST '------------------------------------------------------------------------ Public Class cScale 'I use arraylists because I like them... 'Use Whatever ICollection object you want! Dim values As ArrayList Public Sub New(ByVal Values As ArrayList) Me.values = Values End Sub Public Function GetScaleValues() As ArrayList 'First we have to find the min & max values within the values array '---------------------------------------------------- Dim v As Double Dim max As Double = 0 Dim min As Double = 0 min = values(0) max = values(0) For Each v In values If v < min Then min = v ElseIf v > max Then max = v End If Next '---------------------------------------------------- 'Now for some standard ideas... ' 1st -> I think it's a good idea to set the max and the min values, the closest lower and higher integer ' If the values are already integers we use the same method ' 2nd -> The gap between the values will be always integers ' If you need fractional values you'll have to work out a better algorithm '---------------------------------------------------- 'So, lets find the first scale value Dim minScaleValue As Double 'I use Double for future decimal implementations! If Fix(min) = min Then minScaleValue = min - 1 Else If min > 0 Then minScaleValue = Fix(min) ElseIf min < 0 Then minScaleValue = Fix(min) - 1 ElseIf min = 0 Then minScaleValue = 0 End If End If 'Now, using the same logic, lets find the last scale value Dim maxScaleValue As Double If Fix(max) = max Then maxScaleValue = max + 1 Else If max <> 0 Then maxScaleValue = Fix(max) + 1 ElseIf max = 0 Then maxScaleValue = 0 End If End If 'Ok, now we're almost donne, only remains the scale values gap 'Using the logic I've described in 2... '------------------------------------------------------------- 'As my scale values ar always integers I can do it on the Fro Loop... Dim ScaleValues As New ArrayList For i As Integer = minScaleValue To maxScaleValue Step 1 'Step this way doesn't do anything like this but you can use it too... ScaleValues.Add(i) Next 'Finish... Return ScaleValues End Function End Class Tell me what you think... Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
Ace Master Posted November 27, 2003 Author Posted November 27, 2003 looks good, but how I resize the scale of the chart ? Where is the code for chart scale by those values ? thanks Quote
AlexCode Posted November 27, 2003 Posted November 27, 2003 These questions you meda led me thinking... what kind of code do you have to generate your graphic scale? If it was me who was buildind that graphic control I would have made two collections, one for each axys... This would make it easyer too if in the future you want to make 3D charts too... you only have to add a 3rd axys and mahe the GDI code... I don't even know what kind of graphic you're talkiing about... Tell me more about it... Quote Software bugs are impossible to detect by anybody except the end user.
Ace Master Posted November 27, 2003 Author Posted November 27, 2003 I don't have any code for generate the scaling chart. Is 0-100 by default. I want 0-10 or 0-5 or 0-20 ....etc... picture attached. I tried chart.maxvalue = 10 , and is not working. thanks Quote
AlexCode Posted November 27, 2003 Posted November 27, 2003 Ok, but how do you design the scale? Is it fixed or it's dynamicly disigned? You have to design the scale according do a collection of values. Then, the values you want to display must have a direct relation to that collection. For example: If the scale starts with the number 2, the pixel coordenate that representes the zero scale value, is really representing 2 instead of zero. The one thing you have to keep in mind is that a chart control can't have fixed values, evey thing have to be dynamicly created... Got the idea? Quote Software bugs are impossible to detect by anybody except the end user.
Ace Master Posted November 27, 2003 Author Posted November 27, 2003 uff... I just found my problem. The chart proprieties have one option named autoscale. It wasn�t selected :( Quote
AlexCode Posted November 27, 2003 Posted November 27, 2003 but aren't you building a chart control on your own? :( Quote Software bugs are impossible to detect by anybody except the end user.
Ace Master Posted November 28, 2003 Author Posted November 28, 2003 not realy. I have this chart control, and with some code I populate the chart and change is values , columns, etc... btw. I have mysql connection and one data adapter. I want with this data to populate an multidimensional array. little help here? ..thanks .. just the ideea. I know in php but don't know the vb sintax. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.