private ArrayList<MetricsChartDataGroupNVD3> getMetricsDataJsonNVD3(
      List<Integer> variableIds,
      Integer sensorId,
      Long timestampFrom,
      Long timestampTo,
      Boolean withMinMax,
      String chartType) {

    // if chartType not null, call this
    if (chartType != null) {
      return getMetricsDataJsonNVD3WithChartType(
          variableIds, timestampFrom, timestampTo, chartType);
    }

    // Get sensor variables
    List<SensorVariable> sensorVariables = null;
    if (!variableIds.isEmpty()) {
      sensorVariables = DaoUtils.getSensorVariableDao().getAll(variableIds);
    } else {
      sensorVariables = DaoUtils.getSensorVariableDao().getAllBySensorId(sensorId);
    }
    // Return if no data available
    if (sensorVariables == null) {
      return new ArrayList<MetricsChartDataGroupNVD3>();
    }

    MetricsGraphSettings metricsGraphSettings =
        ObjectFactory.getAppProperties().getMetricsGraphSettings();
    ArrayList<MetricsChartDataGroupNVD3> finalData = new ArrayList<MetricsChartDataGroupNVD3>();

    for (SensorVariable sensorVariable : sensorVariables) {
      MetricsGraph metrics =
          metricsGraphSettings.getMetric(sensorVariable.getVariableType().getText());
      switch (sensorVariable.getMetricType()) {
        case DOUBLE:
          ArrayList<MetricsChartDataNVD3> preDoubleData = new ArrayList<MetricsChartDataNVD3>();

          MetricsDoubleTypeDevice metricQueryDouble =
              MetricsDoubleTypeDevice.builder()
                  .timestampFrom(timestampFrom)
                  .timestampTo(timestampTo)
                  .sensorVariable(sensorVariable)
                  .build();
          List<MetricsDoubleTypeDevice> doubleMetrics =
              DaoUtils.getMetricsDoubleTypeDeviceDao().getAll(metricQueryDouble);
          ArrayList<Object> avgMetricDoubleValues = new ArrayList<Object>();
          ArrayList<Object> minMetricDoubleValues = new ArrayList<Object>();
          ArrayList<Object> maxMetricDoubleValues = new ArrayList<Object>();
          for (MetricsDoubleTypeDevice metric : doubleMetrics) {
            avgMetricDoubleValues.add(new Object[] {metric.getTimestamp(), metric.getAvg()});
            if (withMinMax) {
              minMetricDoubleValues.add(new Object[] {metric.getTimestamp(), metric.getMin()});
              maxMetricDoubleValues.add(new Object[] {metric.getTimestamp(), metric.getMax()});
            }
          }
          preDoubleData.add(
              MetricsChartDataNVD3.builder()
                  .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.AVERAGE))
                  .values(avgMetricDoubleValues)
                  .color(metrics.getColor())
                  .type(metrics.getSubType())
                  .build()
                  .updateSubType(metrics.getType()));
          if (withMinMax) {
            preDoubleData.add(
                MetricsChartDataNVD3.builder()
                    .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.MINUMUM))
                    .values(minMetricDoubleValues)
                    .color(COLOR_MINIMUM)
                    .type(metrics.getSubType())
                    .build()
                    .updateSubType(metrics.getType()));
            preDoubleData.add(
                MetricsChartDataNVD3.builder()
                    .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.MAXIMUM))
                    .values(maxMetricDoubleValues)
                    .color(COLOR_MAXIMUM)
                    .type(metrics.getSubType())
                    .build()
                    .updateSubType(metrics.getType()));
          }
          finalData.add(
              MetricsChartDataGroupNVD3.builder()
                  .metricsChartDataNVD3(preDoubleData)
                  .id(sensorVariable.getId())
                  .unit(sensorVariable.getUnit())
                  .timeFormat(getTimeFormat(timestampFrom))
                  .variableType(
                      ObjectFactory.getMcLocale()
                          .getString(sensorVariable.getVariableType().name()))
                  .dataType(sensorVariable.getMetricType().getText())
                  .resourceName(
                      new ResourceModel(RESOURCE_TYPE.SENSOR_VARIABLE, sensorVariable)
                          .getResourceLessDetails())
                  .chartType(metrics.getType())
                  .chartInterpolate(metrics.getInterpolate())
                  .build());

          break;
        case BINARY:
          ArrayList<MetricsChartDataNVD3> preBinaryData = new ArrayList<MetricsChartDataNVD3>();
          MetricsBinaryTypeDevice metricQueryBinary =
              MetricsBinaryTypeDevice.builder()
                  .timestampFrom(timestampFrom)
                  .timestampTo(timestampTo)
                  .sensorVariable(sensorVariable)
                  .build();
          List<MetricsBinaryTypeDevice> binaryMetrics =
              DaoUtils.getMetricsBinaryTypeDeviceDao().getAll(metricQueryBinary);
          ArrayList<Object> metricBinaryValues = new ArrayList<Object>();
          for (MetricsBinaryTypeDevice metric : binaryMetrics) {
            metricBinaryValues.add(new Object[] {metric.getTimestamp(), metric.getState() ? 1 : 0});
          }
          preBinaryData.add(
              MetricsChartDataNVD3.builder()
                  .key(sensorVariable.getVariableType().getText())
                  .values(metricBinaryValues)
                  .color(metrics.getColor())
                  .type(metrics.getSubType())
                  .build()
                  .updateSubType(metrics.getType()));
          finalData.add(
              MetricsChartDataGroupNVD3.builder()
                  .metricsChartDataNVD3(preBinaryData)
                  .id(sensorVariable.getId())
                  .unit(sensorVariable.getUnit())
                  .timeFormat(getTimeFormat(timestampFrom))
                  .variableType(
                      ObjectFactory.getMcLocale()
                          .getString(sensorVariable.getVariableType().name()))
                  .dataType(sensorVariable.getMetricType().getText())
                  .resourceName(
                      new ResourceModel(RESOURCE_TYPE.SENSOR_VARIABLE, sensorVariable)
                          .getResourceLessDetails())
                  .chartType(metrics.getType())
                  .chartInterpolate(metrics.getInterpolate())
                  .build());
          break;
        default:
          // no need to do anything here
          break;
      }
    }

    return finalData;
  }
  private MetricsChartDataGroupNVD3 getMetricsBatteryJsonNVD3(
      Integer nodeId, Long timestampFrom, Long timestampTo, Boolean withMinMax) {
    ArrayList<MetricsChartDataNVD3> preDoubleData = new ArrayList<MetricsChartDataNVD3>();

    MetricsBatteryUsage metricQueryBattery =
        MetricsBatteryUsage.builder()
            .timestampFrom(timestampFrom)
            .timestampTo(timestampTo)
            .node(Node.builder().id(nodeId).build())
            .build();
    List<MetricsBatteryUsage> batteryMetrics =
        DaoUtils.getMetricsBatteryUsageDao().getAll(metricQueryBattery);
    ArrayList<Object> avgMetricValues = new ArrayList<Object>();
    ArrayList<Object> minMetricValues = new ArrayList<Object>();
    ArrayList<Object> maxMetricValues = new ArrayList<Object>();
    for (MetricsBatteryUsage metric : batteryMetrics) {
      avgMetricValues.add(new Object[] {metric.getTimestamp(), metric.getAvg()});
      if (withMinMax) {
        minMetricValues.add(new Object[] {metric.getTimestamp(), metric.getMin()});
        maxMetricValues.add(new Object[] {metric.getTimestamp(), metric.getMax()});
      }
    }
    MetricsGraph metricBattery =
        ObjectFactory.getAppProperties().getMetricsGraphSettings().getBattery();
    preDoubleData.add(
        MetricsChartDataNVD3.builder()
            .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.AVERAGE))
            .values(avgMetricValues)
            .color(metricBattery.getColor())
            .type(metricBattery.getSubType())
            .build()
            .updateSubType(metricBattery.getType()));
    if (withMinMax) {
      preDoubleData.add(
          MetricsChartDataNVD3.builder()
              .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.MINUMUM))
              .values(minMetricValues)
              .color(COLOR_MINIMUM)
              .type(metricBattery.getSubType())
              .build()
              .updateSubType(metricBattery.getType()));
      preDoubleData.add(
          MetricsChartDataNVD3.builder()
              .key(ObjectFactory.getMcLocale().getString(MC_LOCALE.MAXIMUM))
              .values(maxMetricValues)
              .color(COLOR_MAXIMUM)
              .type(metricBattery.getSubType())
              .build()
              .updateSubType(metricBattery.getType()));
    }

    return MetricsChartDataGroupNVD3.builder()
        .metricsChartDataNVD3(preDoubleData)
        .unit("%")
        .timeFormat(getTimeFormat(timestampFrom))
        .id(nodeId)
        .resourceName(new ResourceModel(RESOURCE_TYPE.NODE, nodeId).getResourceLessDetails())
        .chartType(metricBattery.getType())
        .chartInterpolate(metricBattery.getInterpolate())
        .build();
  }