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);
                    series.Values.Add(curValue);
                }
                chartRanks.Model.PlotAreas[0].Series.Clear();
                chartRanks.Model.PlotAreas[0].Series.Add(series);

     Thanks!

  • Replied 8 September 2017, 2:37 pm EST

    Hello,

    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";
                series.Values.Add(352.0);
                series.Values.Add(3454.0);
                series.Values.Add(3453.0);
                series.Values.Add(355.0);

                YPlotArea plotArea = new YPlotArea();
                plotArea.Location = new PointF(0.2f, 0.2f);
                plotArea.Size = new SizeF(0.6f, 0.6f);
                plotArea.Series.Add(series);
                // 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();
                model.LabelAreas.Add(label);
                model.LegendAreas.Add(legend);
                model.PlotAreas.Add(plotArea);
                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