Search code examples
c#teechart

TeeChart how can I change marks font


I'm trying to make a simple horizontal bar graph and I'm almost done, but for some strange reason I can't find a way to change the font properties of the markers near the series bars (highlighted in the screen).

In this particular case I need to make the font bigger and more readable.

Graph ATM

I'll past the current code below, if any of you guys could point me to the right direction would be really appreciated.

        public static byte[] BarGraphHorizontal(double[] values, string[] names, Color[] colors,
            int width, int height)
        {
            TChart chart = new TChart();
            var series = new HorizBar();

            series.Marks.Visible = true;
            series.Marks.Style = MarksStyles.Percent;
            series.Marks.Pen.Visible = false;
            series.Marks.Font.Size = 20;   // Shouldn't this do what I'm looking for?
            series.Pen.Visible = false;
            series.ColorEach = true;

            var joinedInfo = values.Select((x, i) => new { Value = values[i], Name = names[i], Color = colors[i] })
                .OrderBy(x => x.Value)
                .ToArray();
            for (int i = 0; i < joinedInfo.Length; i++)
            {
                series.Add(joinedInfo[i].Value, joinedInfo[i].Name);
                series.Colors[i] = joinedInfo[i].Color;
            }

            var verticalLine = new ColorLine(chart.Chart);
            verticalLine.Axis = chart.Axes.Bottom;
            verticalLine.Value = 0;
            verticalLine.Pen.Visible = true;
            verticalLine.Pen.Color = Color.Black;

            chart.Axes.Bottom.AxisPen.Visible = false;
            chart.Axes.Bottom.Ticks.Visible = false;
            chart.Axes.Bottom.MinorTicks.Visible = false;
            chart.Axes.Bottom.Labels.ValueFormat = "0.0%";
            chart.Axes.Bottom.Labels.Font.Size = 20;

            chart.Axes.Left.Grid.Visible = false;
            chart.Axes.Left.Labels.Font.Bold = true;
            chart.Axes.Left.Labels.Font.Size = 20;

            chart.Aspect.View3D = false;
            chart.Header.Visible = false;
            chart.Legend.Visible = false;
            chart.Series.Add(series);

            chart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
            chart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
            chart.Panel.Bevel.Width = 0;
            chart.Panel.MarginRight *= 2;
            chart.Graphics3D.BufferStyle = Steema.TeeChart.Drawing.BufferStyle.None;

            using (var memoryStream = new MemoryStream())
            {
                chart.Export.Image.PNG.Width = width + 2;
                chart.Export.Image.PNG.Height = height + 2;
                chart.Export.Image.PNG.Save(memoryStream);
                var result = memoryStream.ToArray();
                result = Utils.RemoveBorder(result, 1);
                return result;
            }
        }

Solution

  • Ok I found the solution.

    I needed to pass the chart to the HorizBar constructor, with this edits made in the Marks property are reflected in the graph.

    Basically the first lines of the function became:

        TChart chart = new TChart();
        var series = new HorizBar(chart.Chart);