c# How to invert Y Axis with Live Charts

后端 未结 1 1923
误落风尘
误落风尘 2021-01-27 04:55

I\'m trying to simply invert the Y Axis so this graph it goes up instead of down.

Starting at 6 going up to 1.

This is the user doc on inverted graphs

ht

1条回答
  •  一个人的身影
    2021-01-27 05:33

    To keep it simple, I would use negative negative values, and then format the labels:

    
            
                
            
            
                
                    
                        
                        
                    
                
            
        
    

    Code Behind:

    Values = new ChartValues
            {
                -1,
                -2,
                -3,
                -4,
                -5,
                -6,
                -7,
                -8,
                -9
            };
    
    Formatter = x => x*-1 + " place";
    

    Edit

    The previous option is an specific solution for this question, to invert an axis you need to:

     var invertedYMapper = LiveCharts.Configurations.Mappers.Xy()
                .X(point => point.X)
                .Y(point => -point.Y);
    
            var lineSeries = new LineSeries
            {
                Values = new ChartValues
                    {
                        new ObservablePoint(0,2),
                        new ObservablePoint(1,5),
                        new ObservablePoint(2,7)
                    }
            };
    
            // set the inverted mapping...
            lineSeries.Configuration = invertedYMapper;
    
            var seriesCollection = new SeriesCollection
            {
                lineSeries
            };
    
            // correct the labels
            var YAxis = new Axis
            {
                LabelFormatter = x => (x * -1).ToString()
            };
            cartesianChart1.AxisY.Add(YAxis);
    
            cartesianChart1.Series = seriesCollection;
    

    0 讨论(0)
提交回复
热议问题