如何将Anychart中的序数颜色转换为线性颜色热图?

huangapple go评论67阅读模式
英文:

How to convert a ordinal color to linear color heatmap in Anychart?

问题

今天我试图在Android Studio中使用Anychart库创建一个2D热图图表。我无法将ordinalcolor转换为linearcolor。有人能帮帮我吗?

简要信息:
在Android Studio中设置gradle:

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.github.AnyChart:AnyChart-Android:1.1.2'
}

热图创建:

HeatMap heatmaps = AnyChart.heatMap();
List<DataEntry> data = new ArrayList<>();

热图数据条目:

for (int i = 0; i < 1; i++) {
    for (int j = 0; j < nx; j++) {
        for (int k = 0; k < nx; k++) {
            data.add(new HeatDataEntry(j + "", k + "", Pressure[i][j][k]));
        }
    }
}

最终图表:

String[] strArray3 = {"#90caf9", "#ffb74d", "#d84315"};
heatmaps.colorScale().colors(strArray3);
heatmaps.data(data);
AnyChartView anyChartView = (AnyChartView) findViewById(R.id.any_chart_view);
anyChartView.setChart(heatmaps);

如何去掉每个颜色块之间的白色空格?
感谢您的帮助。

完整代码:

int nx = 100;
int[][][] Pressure = new int[1][nx][nx];
for (int i = 0; i < 1; i++) {
    for (int j = 0; j < nx; j++) {
        for (int k = 0; k < nx; k++) {
            Pressure[i][j][k] = 50;
        }
    }
}

for (int i = 0; i < 1; i++) {
    for (int j = nx / 2 - 5; j <= nx / 2 + 5; j++) {
        for (int k = nx / 2 - 5; k <= nx / 2 + 5; k++) {
            Pressure[i][j][k] = 20;
        }
    }
}
for (int i = 0; i < 1; i++) {
    for (int j = nx / 2 - 3; j <= nx / 2 + 3; j++) {
        for (int k = nx / 2 - 3; k <= nx / 2 + 3; k++) {
            Pressure[i][j][k] = 2;
        }
    }
}

HeatMap heatmaps = AnyChart.heatMap();
List<DataEntry> data = new ArrayList<>();

for (int i = 0; i < 1; i++) {
    for (int j = 0; j < nx; j++) {
        for (int k = 0; k < nx; k++) {
            data.add(new HeatDataEntry(j + "", k + "", Pressure[i][j][k]));
        }
    }
}
String[] strArray3 = {"#90caf9", "#ffb74d", "#d84315"};
heatmaps.colorScale().colors(strArray3);
heatmaps.data(data);
AnyChartView anyChartView = (AnyChartView) findViewById(R.id.any_chart_view);
anyChartView.setChart(heatmaps);
英文:

Today I was trying to create a 2d heatmap plot using Anychart libraries in android studio. I am unable to convert ordinalcolor to linearcolor. Can someone please help me on this.
Short info:
Setting up the gradle in Android studio:

allprojects {
repositories {
google()
jcenter()
maven { url &#39;https://jitpack.io&#39; }
}

}

dependencies {
implementation &#39;com.android.support:multidex:1.0.3&#39;
implementation &#39;com.github.AnyChart:AnyChart-Android:1.1.2&#39;

Heatmap creation:

    HeatMap heatmaps = AnyChart.heatMap();
List&lt;DataEntry&gt; data = new ArrayList&lt;&gt;();

Heatmap data Entry:

        for (int i = 0; i &lt; 1; i++) {
for (int j = 0; j &lt; nx; j++) {
for (int k = 0; k &lt; nx; k++) {
data.add(new HeatDataEntry(j + &quot;&quot;, k + &quot;&quot;, Pressure[i][j][k]));
}
}
}

Final plot:

   String[] strArray3 = {&quot;#90caf9&quot;, &quot;#ffb74d&quot;, &quot;#d84315&quot;};
heatmaps.colorScale().colors(strArray3);
heatmaps.data(data);
AnyChartView anyChartView = (AnyChartView) findViewById(R.id.any_chart_view);
anyChartView.setChart(heatmaps);

Result_heatmap_view

How can i get rid of the white spaces between each color block?
Thank you for your help.
Complete code:

        int nx=100;
int[][][] Pressure=new int[1][nx][nx];
for (int i=0;i&lt;1;i++) {
for (int j=0;j&lt;nx;j++) {
for (int k=0;k&lt;nx;k++) {
Pressure[i][j][k] = 50;
}
}
}
for (int i=0;i&lt;1;i++) {
for (int j=nx/2-5;j&lt;=nx/2+5;j++) {
for (int k=nx/2-5;k&lt;=nx/2+5;k++) {
Pressure[i][j][k] = 20;
}
}
}
for (int i=0;i&lt;1;i++) {
for (int j=nx/2-3;j&lt;=nx/2+3;j++) {
for (int k=nx/2-3;k&lt;=nx/2+3;k++) {
Pressure[i][j][k] = 2;
}
}
}
HeatMap heatmaps = AnyChart.heatMap();
List&lt;DataEntry&gt; data = new ArrayList&lt;&gt;();
for (int i = 0; i &lt; 1; i++) {
for (int j = 0; j &lt; nx; j++) {
for (int k = 0; k &lt; nx; k++) {
data.add(new HeatDataEntry(j + &quot;&quot;, k + &quot;&quot;, Pressure[i][j][k]));
}
}
}
String[] strArray3 = {&quot;#90caf9&quot;, &quot;#ffb74d&quot;, &quot;#d84315&quot;};
heatmaps.colorScale().colors(strArray3);
heatmaps.data(data);
AnyChartView anyChartView = (AnyChartView) findViewById(R.id.any_chart_view);
anyChartView.setChart(heatmaps);

答案1

得分: 0

目前 Anychart 不具备在热力图中使用线性颜色的功能,因此我们可以使用以下代码来实现:

HeatMap heatmaps = AnyChart.heatMap();
heatmaps.stroke("none");

以去除颜色之间的白色描边。
来源:Anychart 支持部门

英文:

Currently Anychart does not have the capability to use linear color in Heat map so we can use,

HeatMap heatmaps = AnyChart.heatMap();
heatmaps.stroke(&quot;none&quot;);  

To remove the white strokes between the colors.
Source: Anychart support

huangapple
  • 本文由 发表于 2020年9月3日 10:59:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63716146.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定