Setting tick frequency in code

Posted by: lars-fp on 8 September 2017, 2:37 pm EST

  • Posted 8 September 2017, 2:37 pm EST

    I'm creating a chart using C# and having a hard time figuring out how to control the tick marks and y-axis labels programatically.         Can anyone give me some pointers.

     Here's what I have thus far:


                BarSeries series = new BarSeries();
                series.GapWidth = 0;
                for (int i=1;i<100;i++)
                    int curValue = GetValue(i);


  • Replied 8 September 2017, 2:37 pm EST


    Please find below code for setting the tick marks, length of tick marks, gaps between labels and also the orientation of labels on Y axis:-


            private void button2_Click(object sender, EventArgs e)
                BarSeries series = new BarSeries();
                series.SeriesName = "Series 0";

                YPlotArea plotArea = new YPlotArea();
                plotArea.Location = new PointF(0.2f, 0.2f);
                plotArea.Size = new SizeF(0.6f, 0.6f);
                // setting y axis labels and its orientation
                plotArea.YAxes[0].LabelRotationAngle = 60;
                plotArea.YAxes[0].LabelTextDirection = TextDirection.Horizontal;
                // setting gaps between values on Y axis
                plotArea.YAxes[0].AutoLabelUnit = false;
                plotArea.YAxes[0].LabelUnit = 800;
                // setting Major tick marks and its length
                plotArea.YAxes[0].MajorTickLength = 5.0f;
                plotArea.YAxes[0].MajorTickVisible = true;
                // setting Minor tick marks and its length
                plotArea.YAxes[0].MinorTickLength = 1.0f;
                plotArea.YAxes[0].MinorTickVisible = true;

                LabelArea label = new LabelArea();
                label.Text = "Bar Chart";
                label.Location = new PointF(0.5f, 0.02f);
                label.AlignmentX = 0.5f;
                label.AlignmentY = 0.0f;

                LegendArea legend = new LegendArea();
                legend.Location = new PointF(0.98f, 0.5f);
                legend.AlignmentX = 1.0f;
                legend.AlignmentY = 0.5f;

                ChartModel model = new ChartModel();
                fpChart1.Model = model;


    Hope this will help you. Feel free to ask for further clarification. Thanks.

  • Replied 8 September 2017, 2:37 pm EST

    Great..  Thank you.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels