kirsan31 / winforms-datavisualization

System.Windows.Forms.DataVisualization provides charting for WinForms applications.
MIT License
45 stars 19 forks source link

Question: Axis with 2 units #37

Closed paul1956 closed 1 year ago

paul1956 commented 1 year ago

I am plotting on Y2 a value that could be one of 2 units (U1 or U2) as selected by user (think Fahrenheit and Kelvin) the range is 50-400 (always integer) in U1 and 2 to 22 (always integer) in U2 (U1 is 18x U2 or 1/18 of U1). What I am being asked to do is show 50U1/2U2 to 400U1/22U2. Where U1 and U2 are the name of the Unit or are flipped based on user selection. The actual plot is only based on U1. I don't want to plot 2 lines. The Y2 values are basically 6 fixed values than are static for either unit. image

kirsan31 commented 1 year ago

Hi @paul1956. Sorry, but I don't get what are you asking for 😔

paul1956 commented 1 year ago

@kirsan31 I want the label to contain both of the 2 Axises in the image above, in the above example the bottom numbers would be something like 50-2 or 2-50 or (50 mm/dL- 2 mmol/L) and the top value would be 400-22 or 22-400. or have a way to show both Axises i.e. both images above. The second Axis would just be for display nothing would be plotted on it.

The data source can be in mg/dL or mmol/L units. Most users only care about their local units and that is the way it works now. But a few people work with people that use the foreign units and they don't want to have to convert in their heads. The best example is MPH and KPH and imagine someone from Europe driving in US, they want to see both units.

kirsan31 commented 1 year ago

Got it now. You can use custom labels for this.

paul1956 commented 1 year ago

@kirsan31 I am missing something with the code below I get image if you compare the issue directly above with what the top image above, the 400 is not at the top and the 50 is missing. the green line should be at 120 instead it is lower. The code is below

                Dim interval As Single = 70
                For i As Double = 0 To 400 Step 70
                    Dim newLabel As New CustomLabel(i,
                                                    i + interval ,
                                                    (50 + i).ToString,
                                                    0,
                                                    LabelMarkStyle.LineSideMark,
                                                    GridTickTypes.TickMark)
                    .CustomLabels.Add(newLabel)
                Next

Once the 2 images are the same I can get the text to be what I need. The labels look like a range vs a point

paul1956 commented 1 year ago

a better view image

kirsan31 commented 1 year ago

The custom label axis position is the middle of ToPosition and FromPosition. So in your example above for 1 label it's (70 + 0) / 2 == 35. Docs, also you always can look into ChartSamples app (there many good examples).

paul1956 commented 1 year ago

Is there no way to get it to look like a regular label? 50 is a value not a range. i want the second column to look exactly like to first for now until I understand how it works

kirsan31 commented 1 year ago

Is there no way to get it to look like a regular label? 50 is a value not a range.

I don't get in what you have problems - you have a tool to place a label with any text in any place on axis 🤷‍♂️ I would try to set (ToPosition + FromPosition) / 2 == 50 for 1 label...

paul1956 commented 1 year ago

Thanks that is what I was missing.