简体   繁体   中英

WinForms scatter chart reversed Y axis

I want a simple scatter chart with the Y axis reversed (lowest number at the top largest at the bottom). I can do this in Excel by setting the y-axis options:

Horizontal axis crosses : Maximum axis value Values in reverse order

Now I want to create my own application using the WinForms (C#) chart control to do the same thing. So I set the Y-axis Is-Reversed to true, and crossing to max. But the x-axis labels are inside the chart area and not below the axis.

Is there anyway to set the x-axis labels to be below the x-axis (bottom of the chart) as you would normally expect them to be?

The simplest way I can think of is to add secondary Axes and hide those labels you don't want to show by manipulating their color:

After setting up my chart references..

chart1.Series.Clear();                     
chart1.ChartAreas.Clear();
ChartArea CA = chart1.ChartAreas.Add("CA");  
Series S1 = chart1.Series.Add("S1");
S1.ChartType = SeriesChartType.Point;

.. I set up the axes:

CA.AxisX2.Enabled = AxisEnabled.True;     // show the secondary x-axis
CA.AxisY2.Enabled = AxisEnabled.True;     // show the secondary y-axis

CA.AxisY.IsReversed = true;
CA.AxisY.Crossing = 100;                  // use your maximum!

CA.AxisX.LabelStyle.ForeColor = Color.Transparent;   // hide the normal x-axis labels
CA.AxisY2.LabelStyle.ForeColor = Color.Transparent;  // hide the secondary y-axis labels

CA.AxisY2.Crossing = 100;                // bind the secondary axis to your maximum

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM