我自己的d3自定义色阶-插值范围从给定的十六进制到另一个

时间:2018-11-15 07:33:40

标签: d3.js

我无法创建自定义色标。我想让d3插值范围从一个十六进制到另一个十六进制

  const colorRange = ['#d7191c', '#d55045']
  const data = [617, 631, 640, 650]
  const color = d3
    .scaleLinear()
    .domain(1, data.length)
    .interpolate(d3.interpolateHcl)
    .range([d3.hcl(colorRange[1]), d3.hcl(colorRange[0])])
  console.log(color(1)) // returns 'rgb(0,0,0)' but expected some hex from the gradient from '#d55045' to '#d7191c'

1 个答案:

答案 0 :(得分:0)

您需要正确指定域

private string GetKey()
        {                
            using (StreamReader reader = new StreamReader(@"/storage/emulated/0/MyCertP.p12"))
            {
                var fs = reader.BaseStream;
                KeyStore keystore = KeyStore.GetInstance("PKCS12");
                keystore.Load(fs, "cli7890".ToCharArray());

                var enm = keystore.Aliases();
                String keyAlias = "";
                while (enm.HasMoreElements)
                {
                    keyAlias = (String)enm.NextElement();
                    var _certificate = keystore.GetCertificate(keyAlias);
                    var _publicKey = _certificate.PublicKey;
                }
                var  key = keystore.GetKey(keyAlias, "cli7890".ToCharArray());

                KeyStore.PrivateKeyEntry keyEnt = (KeyStore.PrivateKeyEntry)keystore.GetEntry(keyAlias, new KeyStore.PasswordProtection("cli7890".ToCharArray()));

                return keyEnt.PrivateKey.ToString();

            }

        }
const colorRange = ['#d7191c', '#d55045']
const data = [617, 631, 640, 650]
const color = d3.scaleLinear()
  .domain([1, data.length])
  .interpolate(d3.interpolateHcl)
  .range([d3.hcl(colorRange[1]), d3.hcl(colorRange[0])])
console.log(color(1));