How to set the X with category data?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to set the X with category data?

Post by Marc » Mon Aug 28, 2023 11:45 am

Hello,

Not sure, I thought I had understood correctly. That the goal is to line up the charts (?). The principle is the same in this case. To modify chart settings to obtain the required result.

ie.
AlignedCharts.jpg
AlignedCharts.jpg (41.64 KiB) Viewed 23235 times
Very unrefined code to achieve these charts is included here:

Code: Select all

Line line1;
Line line2;
Line line3;

public Form1()
{
    InitializeComponent();

    line1 = new Line(tChart1.Chart);
    line2 = new Line(tChart1.Chart);

    line3 = new Line(tChart2.Chart);

    var product1 = "P1";
    var product2 = "P2";

    InitializeChart(line1, product1, Color.Red);
    InitializeChart(line2, product2, Color.Blue);

    InitializeChart2(line3,Color.Red);
    line3.Add(0, 10, "P1");
    line3.Add(1, 18, "P2");
    line3.Marks.Visible = true;
    line3.Marks.Style = MarksStyles.LabelValue;

    tChart1.Legend.Visible = false;
    tChart2.Legend.Visible = false;

    tChart1.Axes.Bottom.SetMinMax(-1, 2);
    tChart1.Axes.Bottom.Grid.DrawEvery = 1;

    tChart2.Axes.Bottom.SetMinMax(-1, 2);
    tChart2.Axes.Bottom.Grid.DrawEvery = 1;

    tChart2.Axes.Left.SetMinMax(0, 20);
    tChart1.Axes.Left.Labels.Size.Width = 10;
    tChart1.Axes.Left.Labels.Size.Width = 10;

    tChart1.Axes.Bottom.Labels.Items.Add(0, product1);
    tChart1.Axes.Bottom.Labels.Items.Add(1, product2);

    tChart2.Axes.Bottom.Labels.Items.Add(0, "");
    tChart2.Axes.Bottom.Labels.Items.Add(1, "");
    tChart2.Axes.Bottom.Labels.Visible = false;

    tChart1.Axes.Bottom.Grid.Visible = true;
    tChart2.Axes.Bottom.Grid.Visible = true;
}

public class ProductInfo
{
    public string Product { get; set; }
    public int Y { get; set; }
    public int X { get; set; }
}

List<ProductInfo> list = new List<ProductInfo>()
{
    new ProductInfo() { X = 0,  Product = "P1", Y = 10 },
    new ProductInfo() { X = 0, Product = "P1", Y = 15 },
    new ProductInfo() { X = 0, Product = "P1", Y = 6 },
    new ProductInfo() { X = 1, Product = "P2", Y = 22 },
    new ProductInfo() { X = 1, Product = "P2", Y = 18 }
};

private void InitializeChart2(Line line, Color color)
{
    line.LinePen.Width = 3;
    line.Color = color;
    line.Pointer.Visible = true;
    line.Pointer.Style = PointerStyles.Circle;
}

private void InitializeChart(Line line, string select, Color color)
{
    line.LinePen.Width = 3;
    line.Color = color;
    line.Pointer.Visible = true;
    line.Pointer.Style = PointerStyles.Circle;
    line.YValues.DataMember = "Y";
    line.XValues.DataMember = "X";
    line.LabelMember = "Product";
    line.Title = select;
    line.Add(list.Where(x => x.Product == select).ToList() as IList);
}

private void tChart2_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
{
    if (((Axis)sender).Horizontal)
        e.LabelText = "";
}
Regards,
Marc
Steema Support

coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Re: How to set the X with category data?

Post by coldwind » Mon Aug 28, 2023 12:07 pm

Question1:How do I find the maximum distance to the left of four graphs and set this maximum distance for all graphs
four chart.png
four chart.png (58.99 KiB) Viewed 23234 times
Question2:The X-axis label in the last figure is too long. I hope it can be displayed as a line wrap if it is too long, and the spacing between X-axis points and points can be widened
Line feed example.png
Line feed example.png (62.38 KiB) Viewed 23234 times

coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Re: How to set the X with category data?

Post by coldwind » Tue Aug 29, 2023 7:05 am

The X-axis names of the first five points in the red box are the same, I hope that each point can correspond to its own X-axis label, and then each point should have vertical lines, such as the gray line I hand-painted in the red box (it should be tchart.Axes.Bottom.Grid), I expect that each point has a corresponding X-axis. And they all have Axes.Bottom.Grid
Grid.png
Grid.png (98.24 KiB) Viewed 23212 times

coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Re: How to set the X with category data?

Post by coldwind » Wed Aug 30, 2023 2:20 am

Hope to reply as soon as possible, thank you

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to set the X with category data?

Post by Christopher » Wed Aug 30, 2023 8:45 am

Hello,
coldwind wrote:
Wed Aug 30, 2023 2:20 am
Hope to reply as soon as possible, thank you
The subject of this help topic is 'How to set the X with category data?', but you are now asking for help in how to 'hand paint' lines on the Chart and how to customize bottom axis labels. Would you please be so kind as to split your questions into different topics? This will make it easier for customers to find answers to their own questions by searching these forums (there are plenty of questions and answers on these forums concerning custom painting on the Chart and customization of Axis Labels).
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply