Skip to content

UIBarChart Bug #84

Description

@AngeloCresta

Hi, the series have wrong colors:
SunnyUI-BarChartError

I've modified the DrawSeries in (UIBarChart.cs) method as follow:

        protected virtual void DrawSeries(Graphics g, List<UIBarSeries> series)
        {
            if (series == null || series.Count == 0) return;
            using var TempFont = Font.DPIScaleFont(UIStyles.DefaultSubFontSize);
            for (int i = 0; i < Bars.Count; i++)
            {
                var bars = Bars[i];
                foreach (var info in bars)
                {
                    Color color = ChartStyle.GetColor(i);

                    g.FillRectangle(color, info.Rect);

                    if (Option.ShowValue)
                    {
                        string value = info.Value.ToString("F" + info.Series.DecimalPlaces);
                        if (info.Top)
                        {
                            g.DrawString(value, TempFont, color, new Rectangle((int)info.Rect.Center().X - Width, (int)info.Rect.Top - Height, Width * 2, Height), ContentAlignment.BottomCenter);
                        }
                        else
                        {
                            g.DrawString(value, TempFont, color, new Rectangle((int)info.Rect.Center().X - Width, (int)info.Rect.Bottom, Width * 2, Height), ContentAlignment.TopCenter);
                        }
                    }
                }
            }

            for (int i = 0; i < Option.XAxis.Data.Count; i++)
            {
                Bars[0][i].Size = TextRenderer.MeasureText(Bars[0][i].Tips, TempFont);
            }
        }

having the expected result:
SunnyUI-BarChartFixed

Regards,
Angelo

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions