using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;

namespace HideYAxisLablesWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            List<ChartData> data = new List<ChartData>();
            data.Add(new ChartData("Text1", 5, -25));
            data.Add(new ChartData("Text2", 10, -50));
            data.Add(new ChartData("Text3", 25, -70));
            radChart.ItemsSource = data;

            SeriesMapping firstSeriesMapping = new SeriesMapping();
            firstSeriesMapping.SeriesDefinition = new BarSeriesDefinition();
            firstSeriesMapping.ItemMappings.Add(new ItemMapping("Title", DataPointMember.XCategory));
            firstSeriesMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));

            SeriesMapping secondSeriesMapping = new SeriesMapping();
            secondSeriesMapping.SeriesDefinition = new LineSeriesDefinition();
            secondSeriesMapping.SeriesDefinition.AxisName = "secondary";
            secondSeriesMapping.ItemMappings.Add(new ItemMapping("Title", DataPointMember.XCategory));
            secondSeriesMapping.ItemMappings.Add(new ItemMapping("Value2", DataPointMember.YValue));
            //radChart.SeriesMappings.Add(secondSeriesMapping);


            //define the second axes
            AxisY axisY1 = new AxisY();
            axisY1.AxisName = "secondary";
            axisY1.AutoRange = false;
            axisY1.MinValue = -100;
            axisY1.MaxValue = 100;
            axisY1.Step = 50;

            //hides negative tickpoints
            foreach (TickPoint point in axisY1.TickPoints)
            {
                if (point.Value < 0)
                {
                    point.Label = " ";
                }
            }

            //add the second axis as additional YAxes
            radChart.DefaultView.ChartArea.AdditionalYAxes.Add(axisY1);

            //define the first YAxis min, max and step values
            radChart.DefaultView.ChartArea.AxisY.AutoRange = false;
            radChart.DefaultView.ChartArea.AxisY.MinValue = 0;
            radChart.DefaultView.ChartArea.AxisY.MaxValue = 30;
            radChart.DefaultView.ChartArea.AxisY.Step = 5;

            //add series to the chart
            radChart.SeriesMappings.Add(firstSeriesMapping);
            radChart.SeriesMappings.Add(secondSeriesMapping);
        }

        public class ChartData
        {
            public ChartData(string title, double? value, double? value2)
            {
                this.Title = title;
                this.Value = value;
                this.Value2 = value2;
            }

            public string Title { get; set; }
            public double? Value { get; set; }
            public double? Value2 { get; set; }
        }
    }
}
