0

Dear coders out there,

I'm trying to create a chart with an Y-Axis that consists of ASCII characters (e.g. Hx 41 - A till Hx 46 F) This is used to show grades in a control chart. I've searched multiple websites but (maybe I'm not searching correctly) I cannot find what I'm looking for.

What do I have now:
- My Y-Axis now contains numbering (Hex. 41 till 46) - My Y-Axis is not formatted yet in any way, only min and max values filled by code below

            if (measurementData.Max() >= Usl) maxValue = measurementData.Max();
            else if (measurementData.Max() < Usl) maxValue = Usl + 0.1;

            if (measurementData.Min() <= Lsl) minValue = measurementData.Min();
            else if (measurementData.Min() > Lsl) minValue = Lsl - 0.1;

What do I want:
- My Y-Axis is to show 'A' till 'F' (instead of Hex. 41 till 46)

Jordski91
  • 1
  • 4
  • What are you targetting: Winforms, WPF, ASP..? Always __TAG__ your question correctly! - Assuming Winforms and MSChart: You can set the X-AxisLabel for each DataPoint. For Y-AxisLabels this is not possible, as many points can have the same y-value. Instead you would set CustomLabels. If you want a code example you need to show the code you have so far. – TaW May 15 '18 at 10:05
  • Sorry, from WPF I'm opening a Winforms. After this i'm creating a minimum and maximum for the Axis-Y based on my data. Can you provide me with a good CustomLabels example? I've tried reading up on it but so far the things i tried are not working. At this point I do not do any settings to the Axis-Y – Jordski91 May 15 '18 at 10:21
  • I have writen [a few examples](https://stackoverflow.com/search?q=user%3A3152130+CustomLabels), some for the x- and some for the y-axis. The key is always to understand the basics, ie that you need to have a pair of a FromPosition and a ToPosition. Also that internally all values are doubles. So if you really have values going from x41-x46 ie from 65-70 the first label could have 64.9 and 65.1 and so forth. – TaW May 15 '18 at 10:33
  • I'll be afk for a day. If you can post an image of what you want it'll be easier to help tomorrow.. – TaW May 15 '18 at 11:13

1 Answers1

0

After looking around a bit more... I found a solution:

Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add(0.5, 1.5, "yr1")
Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add(1.5, 2.5, "yr2")
Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add(2.5, 3.5, "yr3")

Used the example above and modified it to following:

crtProces.ChartAreas[0].AxisY.CustomLabels.Clear();
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(40.5, 41.5, "A");
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(41.5, 42.5, "B");
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(42.5, 43.5, "C");
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(43.5, 44.5, "D");
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(44.5, 45.5, "E");
crtProces.ChartAreas[0].AxisY.CustomLabels.Add(45.5, 46.5, "F");

My next question would be, how can this be made variable? Now the increments are filled in manually (40.5 - 41.5) but how can this be done in a for loop?

enter image description here

TaW
  • 53,122
  • 8
  • 69
  • 111
Jordski91
  • 1
  • 4
  • [Here](https://stackoverflow.com/questions/33556991/windows-forms-chart-set-fixed-mixed-labels/33559004#33559004) is a simple example with a for loop. But the real issue is to know the rules. You can have a counter or you can loop over the values from axis.Minimum to axis.Maximum with axis.Interval as step. But the rules are key and you need to decide on them! - In your example: What should the dynamics be: When Looping over a larger number should it be creating more letters? Or should the same number of grades be alotted to different number? – TaW May 16 '18 at 21:02
  • Basically what this example is showing is a DMC quality grading, so the letters A to F are fixed (this is based on spec). In my opinion creating a loop would mean writing less code. The example you send me is great! I can use it! I'm seeing some questionmarks in that code which is new for me but I will comment over there in order to keep things neat. Thanks! – Jordski91 May 17 '18 at 16:56