gpt4 book ai didi

android - 无法用双倍值更新我的热图 scichart

转载 作者:搜寻专家 更新时间:2023-11-01 08:22:59 25 4
gpt4 key购买 nike

我正在开发 android 应用程序,我从压力传感器(连接到 arduino)接收数据并希望在 scichart 热图中显示它。我使用 IPaletteProvider 成功创建了 scichart 热图。现在我想用压力传感器更新热图,但目前我无法更新我的热图。这是我的整体(PressureActivity 代码)。

 public class PressureSensorActivity extends AppCompatActivity {
private String TAG="PressureSensorActivity";
private BluetoothAdapter mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
// private HeatMap heatMap;
private TextView pressureTextView;
private SciChartSurface chart;
private static final int WIDTH = 300, HEIGHT = 200;
private FastUniformHeatmapRenderableSeries heatmapRenderableSeries;
private BroadcastReceiver mReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Constants.DATA)) {
String data = intent.getStringExtra("DATA");
if (data.contains("ccccc")) {
Log.d("DATA contain weight tag", data);
int index = data.indexOf('/');
int indexx = data.indexOf('#');
String d = data.substring((index + 1), indexx);
Log.d(TAG + "Reduce data", d);
pressureTextView.setText(Integer.parseInt(d)+" psi");
DoubleValues doubleValues=new DoubleValues(1);
doubleValues.add(Double.parseDouble(d));
dataSeries.updateZValues(doubleValues);

}
}
else if (intent.getAction().equals(Constants.DISCONNECTED)) {
Toast.makeText(PressureSensorActivity.this, "Disconnected...", Toast.LENGTH_SHORT).show();
startActivity(new Intent(PressureSensorActivity.this, MainActivity.class));
PressureSensorActivity.this.finish();
}
}
};
private final UniformHeatmapDataSeries<Integer, Integer, Double> dataSeries =
new UniformHeatmapDataSeries<>(Integer.class, Integer.class, Double.class, WIDTH, HEIGHT);
// private SciChartBuilder sciChartBuilder = SciChartBuilder.init(this);
private final IPaletteProvider paletteProvider=new CustomUniformHeatMapProvider();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pressure_sensor);
SpannableString s = new SpannableString("Pressure Sensor");
s.setSpan(new ForegroundColorSpan(Color.BLACK), 0,"Pressure Sensor".length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);
pressureTextView=findViewById(R.id.pressure_value_text_view);
chart=findViewById(R.id.heatmap);
SciChartBuilder.init(this);
SciChartBuilder sciChartBuilder=SciChartBuilder.instance();
final NumericAxis xAxis = sciChartBuilder.newNumericAxis().build();
final NumericAxis yAxis = sciChartBuilder.newNumericAxis().build();

FastUniformHeatmapRenderableSeries heatmapRenderableSeries = sciChartBuilder.newUniformHeatmap()
.withColorMap(new ColorMap(new int[]{DarkBlue, CornflowerBlue, DarkGreen, Chartreuse, Yellow, Red}, new float[]{0f, 0.2f, 0.4f, 0.6f, 0.8f, 1}))
.withMinimum(0)
.withMaximum(200)
.withDataSeries(dataSeries)
.withPaletteProvider(paletteProvider)
.build();

SciChartHeatmapColourMap colourMap=findViewById(R.id.heatmapColourMap);
colourMap.setMinimum(heatmapRenderableSeries.getMinimum());
colourMap.setMaximum(heatmapRenderableSeries.getMaximum());
colourMap.setColorMap(heatmapRenderableSeries.getColorMap());
Collections.addAll(chart.getXAxes(), xAxis);
Collections.addAll(chart.getYAxes(), yAxis);
Collections.addAll(chart.getRenderableSeries(), heatmapRenderableSeries);
ModifierGroup modifiers = sciChartBuilder.newModifierGroupWithDefaultModifiers()
.withCursorModifier().withShowTooltip(true).withReceiveHandledEvents(true).build()
.build();
Collections.addAll(chart.getChartModifiers(), modifiers);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,new IntentFilter(Constants.DISCONNECTED));
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,new IntentFilter(Constants.DATA));
}

@Override
protected void onDestroy() {
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
this.finish();
}

private class CustomUniformHeatMapProvider extends PaletteProviderBase<FastUniformHeatmapRenderableSeries> implements IUniformHeatmapPaletteProvider {
private double thresholdValue;
public CustomUniformHeatMapProvider()
{
super(FastUniformHeatmapRenderableSeries.class);
}

public void setThresholdValue(double thresholdValue) {
this.thresholdValue = thresholdValue;
if(renderableSeries != null)
renderableSeries.invalidateElement();
}

@Override
public boolean shouldSetColors() {
return false;
}
@Override
public void update() {
final FastUniformHeatmapRenderableSeries renderableSeries = this.renderableSeries;
final UniformHeatmapRenderPassData currentRenderPassData = (UniformHeatmapRenderPassData) renderableSeries.getCurrentRenderPassData();
final DoubleValues zValues = currentRenderPassData.zValues;
final IntegerValues zColors = currentRenderPassData.zColors;
final int size = zValues.size();
zColors.setSize(size);
// working with array is much faster than calling set() many times
final double[] zValuesArray = zValues.getItemsArray();
final int[] zColorsArray = zColors.getItemsArray();
for (int zIndex = 0; zIndex < size; zIndex++) {
final double value = zValuesArray[zIndex];
Log.d(TAG+" zValuesArray",String.valueOf(value));
Log.d(TAG+" zColorsArray",String.valueOf(zColorsArray[zIndex]));

zColorsArray[zIndex] = value > thresholdValue ? Color.BLACK : Color.BLUE;
}
}
}
}

这是我的热图图表的结果,但我无法通过 ZValues 更新它。任何人有任何想法请帮助我。提前致谢。

Here is my resultant heatmap chart

最佳答案

正如我从您的代码中看到的,您的热图大小为 300x200 个单元格:

   private static final int WIDTH = 300, HEIGHT = 200;
private final UniformHeatmapDataSeries<Integer, Integer, Double> dataSeries =
new UniformHeatmapDataSeries<>(Integer.class, Integer.class, Double.class, WIDTH, HEIGHT);

但是您只更新单个 zValue,而 dataSeries 中的其他 zValue 将保留默认的 double 值:

   DoubleValues doubleValues=new DoubleValues(1);
doubleValues.add(Double.parseDouble(d));
dataSeries.updateZValues(doubleValues);

要修复代码,您需要在 doubleValues 中至少有 60000 个项目(它可以有更多但只有第一个 WIDTH * HEIGHT 元素将被复制并由热图显示)在 doubleValues 中,这样热图中的所有单元格都将具有非默认值:

   DoubleValues doubleValues=new DoubleValues();
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
doubleValues.add(value);
}
}
dataSeries.updateZValues(doubleValues);

或者你可以一个一个地更新你的数据系列的 zValues 但它会慢得多,因为 zValue 是通用参数并且结果双值将被装箱/取消装箱:

   for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
dataSeries.updateZAt(x, y, value);
}
}

披露:我是 SciChart Android 团队的首席开发人员

关于android - 无法用双倍值更新我的热图 scichart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48548309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com