【问题标题】:OxyPlot heatmap rectangle commentsOxyPlot 热图矩形注释
【发布时间】:2018-09-07 05:52:48
【问题描述】:

最近我一直在使用 OxyPlot 库做一些图表。我想知道是否可以为每个矩形创建一个带有 cmets 的热图。期待答案。

【问题讨论】:

标签: c# f# oxyplot


【解决方案1】:

我终于发现我需要创建一个新类并扩展热图系列并重写 RenderLabels 方法以更改其功能。

protected override void RenderLabels(IRenderContext rc, OxyRect rect)
    {
        var clip = this.GetClippingRect();
        int m = this.Data.GetLength(0);
        int n = this.Data.GetLength(1);
        double fontSize = (rect.Height / n) * this.LabelFontSize;

        double left = this.X0;
        double right = this.X1;
        double bottom = this.Y0;
        double top = this.Y1;

        var s00 = this.Orientate(this.Transform(left, bottom)); // disorientate
        var s11 = this.Orientate(this.Transform(right, top)); // disorientate

        double sdx = (s11.X - s00.X) / (m - 1);
        double sdy = (s11.Y - s00.Y) / (n - 1);

        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                var point = this.Orientate(new ScreenPoint(s00.X + (i * sdx), s00.Y + (j * sdy))); // re-orientate
                var v = GetValue(this.Data, i, j);
                var color = this.ColorAxis.GetColor(v);
                var hsv = color.ToHsv();
                var textColor = hsv[2] > 0.6 ? OxyColors.Black : OxyColors.White;
                var label = this.Labels[i, j];
                rc.DrawClippedText(
                    clip,
                    point,
                    label,
                    textColor,
                    this.ActualFont,
                    fontSize,
                    500,
                    0,
                    HorizontalAlignment.Center,
                    VerticalAlignment.Middle);
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2019-07-13
    • 1970-01-01
    • 2016-01-14
    • 2019-03-16
    • 1970-01-01
    相关资源
    最近更新 更多