When I open the activity with the chart , I see a black screen. And there is no graph displayed.
I have a trial license key which is valid.
Here is my full code:
xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/chart_layout"
android:orientation="vertical">
Activity:
public class ECGMonitorFragment extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
com.scichart.charting.visuals.SciChartSurface.setRuntimeLicenseKey("");
} catch(Exception e){
Log.e("SciChart", "Error while accesing the license", e);
}
setContentView(R.layout.activity_ecgmonitor_fragment);
// Create a SciChartSurface
final SciChartSurface surface = new SciChartSurface(this);
// Get a layout declared in "activity_main.xml" by id
LinearLayout chartLayout = (LinearLayout) findViewById(R.id.chart_layout);
// Add the SciChartSurface to the layout
chartLayout.addView(surface);
// Initialize the SciChartBuilder
SciChartBuilder.init(this);
// Obtain the SciChartBuilder instance
final SciChartBuilder sciChartBuilder = SciChartBuilder.instance();
// Create a numeric X axis
final IAxis xAxis = sciChartBuilder.newNumericAxis()
.withAxisTitle("X Axis Title")
.withVisibleRange(-5, 15)
.build();
// Added in Tutorial #8 - two Y axes
// Create a numeric axis, right-aligned
final IAxis yAxisRight = sciChartBuilder.newNumericAxis()
.withAxisTitle("Primary")
// Assign a unique ID to the axis
.withAxisId("primaryYAxis")
.withAxisAlignment(AxisAlignment.Right)
.build();
// Create another numeric axis, left-aligned
final IAxis yAxisLeft = sciChartBuilder.newNumericAxis()
.withAxisTitle("Secondary")
// Assign a unique ID to the axis
.withAxisId("secondaryYAxis")
.withAxisAlignment(AxisAlignment.Left)
.withGrowBy(0.2,0.2)
.build();
// Add both Y axes to the YAxes collection of the surface
Collections.addAll(surface.getYAxes(), yAxisLeft, yAxisRight);
// Added in Tutorial #3
// Add a bunch of interaction modifiers to a ModifierGroup
ModifierGroup chartModifiers = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withPinchZoomModifier().build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.withZoomExtentsModifier().withReceiveHandledEvents(true).build()
.withXAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Scale).withClipModeX(ClipMode.None).build()
.withYAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Pan).build()
.build();
// Add the X axis to the XAxes collection of the surface
Collections.addAll(surface.getXAxes(), xAxis);
// Add the interactions to the ChartModifiers collection of the surface
Collections.addAll(surface.getChartModifiers(), chartModifiers);
// Added in Tutorial #6 - FIFO (scrolling) series
// Create a couple of DataSeries for numeric (Int, Double) data
// Set FIFO capacity to 500 on DataSeries
final int fifoCapacity = 500;
final XyDataSeries lineData = sciChartBuilder.newXyDataSeries(Integer.class, Double.class)
.withFifoCapacity(fifoCapacity)
.build();
final XyDataSeries scatterData = sciChartBuilder.newXyDataSeries(Integer.class, Double.class)
.withFifoCapacity(fifoCapacity)
.build();
// Create and configure a line series
final IRenderableSeries lineSeries = sciChartBuilder.newLineSeries()
.withDataSeries(lineData)
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withStrokeStyle(ColorUtil.LightBlue, 2f, true)
.build();
// Create an Ellipse PointMarker for the Scatter Series
EllipsePointMarker pointMarker = sciChartBuilder
.newPointMarker(new EllipsePointMarker())
.withFill(ColorUtil.LightBlue)
.withStroke(ColorUtil.Green, 2f)
.withSize(10)
.build();
// Create and configure a scatter series
final IRenderableSeries scatterSeries = sciChartBuilder.newScatterSeries()
.withDataSeries(scatterData)
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withPointMarker(pointMarker)
.build();
// Add a RenderableSeries onto the SciChartSurface
surface.getRenderableSeries().add(scatterSeries);
surface.getRenderableSeries().add(lineSeries);
surface.zoomExtents();
// Added in Tutorial #5
// Create a LegendModifier and configure a chart legend
ModifierGroup legendModifier = sciChartBuilder.newModifierGroup()
.withLegendModifier()
.withOrientation(Orientation.HORIZONTAL)
.withPosition(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 10)
.build()
.build();
// Add the LegendModifier to the SciChartSurface
surface.getChartModifiers().add(legendModifier);
// Create and configure a CursorModifier
ModifierGroup cursorModifier = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withCursorModifier().withShowTooltip(true).build()
.build();
// Add the CursorModifier to the SciChartSurface
surface.getChartModifiers().add(cursorModifier);
// Added in Tutorial #9 - one more SciChartSurface
final SciChartSurface surface2 = new SciChartSurface(this);
// Add the SciChartSurface to the layout
chartLayout.addView(surface2);
// Set layout parameters for both surfaces
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
surface.setLayoutParams(layoutParams);
surface2.setLayoutParams(layoutParams);
// Create a numeric X axis
final IAxis xAxis2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("X Axis Title")
.withVisibleRange(-5, 15)
.build();
// Create a numeric axis
final IAxis yAxisRight2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("Primary")
.withAxisId("primaryYAxis")
.withAxisAlignment(AxisAlignment.Right)
.build();
// Create another numeric axis
final IAxis yAxisLeft2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("Secondary")
.withAxisId("secondaryYAxis")
.withAxisAlignment(AxisAlignment.Left)
.withGrowBy(0.2, 0.2)
.build();
// Add the Y axis to the YAxes collection of the surface
Collections.addAll(surface2.getYAxes(), yAxisLeft2, yAxisRight2);
// Add the X axis to the XAxes collection of the surface
Collections.addAll(surface2.getXAxes(), xAxis2);
// Create and configure an area series
final IRenderableSeries areaSeries = sciChartBuilder.newMountainSeries()
.withDataSeries(scatterData)
.withYAxisId("primaryYAxis")
.withStrokeStyle(ColorUtil.LightBlue, 2f, true)
.withAreaFillColor(ColorUtil.argb(ColorUtil.LightSteelBlue, 0.6f))
.build();
// Add the area series to the RenderableSeries collection of the surface
Collections.addAll(surface2.getRenderableSeries(), areaSeries);
// Create the second collection of chart modifiers
ModifierGroup chartModifiers2 = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withZoomExtentsModifier().withReceiveHandledEvents(true).build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.withPinchZoomModifier().withReceiveHandledEvents(true).build()
.withCursorModifier().withReceiveHandledEvents(true).build()
.build();
// Add the interactions to the ChartModifiers collection of the surface
Collections.addAll(surface2.getChartModifiers(), chartModifiers2);
TimerTask updateDataTask = new TimerTask() {
private int x = 0;
@Override
public void run() {
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
lineData.append(x, Math.sin(x * 0.1));
scatterData.append(x, Math.cos(x * 0.1));
// Added in Tutorial #7
// Add an annotation every 100 data points
if(x%100 == 0) {
TextAnnotation marker = sciChartBuilder.newTextAnnotation()
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withIsEditable(false)
.withText("N")
.withBackgroundColor(ColorUtil.Green)
.withX1(x)
.withY1(0.0)
.withVerticalAnchorPoint(VerticalAnchorPoint.Center)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withFontStyle(20, ColorUtil.White)
.withZIndex(1)
.build();
surface.getAnnotations().add(marker);
// Remove one annotation from the beginning
// in the FIFO way
if(x > fifoCapacity){
surface.getAnnotations().remove(0);
}
}
// Zoom series to fit the viewport
surface.zoomExtents();
surface2.zoomExtents();
++x;
}
});
}
};
Timer timer = new Timer();
long delay = 0;
long interval = 10;
timer.schedule(updateDataTask, delay, interval);
}
}
- Aditya Kadambi asked 3 years ago
- last edited 3 years ago
- You must login to post comments
Hi there,
I tried to adapt your code to run in one of examples from demo application since you didn’t provide entire project which I could run. Everything seems to work there ( please take a look on attached screenshot ). Can you provide a link on Github with project ( or upload zip with project somewhere else ) with full project so I could debug your code without any changes on my side?
Best regards,
Yura
- Yura Khariton answered 3 years ago
-
Still i see it has black screen. So i have created a new android projected added all the dependencies and put mainactivity.java withe above code and xml file. But i get below error: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.moxca.myapplication, PID: 13408 java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of ‘java.lang.invoke.LambdaMetafactory’ appears in /apex/com.android.runtime/javalib/core-oj.jar) at com.scichart.charting.model.ChartModifierCollectionCore.(SourceFile:23) at com.scichart.charting.model.ChartModifierCollectionCore.(SourceFile:1) at com.scichart.charting.model.ChartModifierCollectionBase.(SourceFile:1) at com.scichart.charting.model.ChartModifierCollection.(SourceFile:1) at com.scichart.charting.visuals.SciChartSurface.a(SourceFile:35) at com.scichart.charting.visuals.SciChartSurface.(SourceFile:167) at com.moxca.myapplication.MainActivity.onCreate(MainActivity.java:43)
-
I haven’t seen such exception before. Do you use ProGuard or some other tool which may strip methods away? Usually NoSuchMethodError is thrown in runtime if for some reason method was removed from compiled app or you use Android OS version which doesn’t provide such API. What device are you using for testing? Can you provide entire project which reproduces this issue( via Github or upload zip with project as attachment ) so I can debug it on my PC?
- You must login to post comments
I have defined surface too. Here is the full code:
ECGMonitorFragment.java
public class ECGMonitorFragment extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
com.scichart.charting.visuals.SciChartSurface.setRuntimeLicenseKey("");
} catch(Exception e){
Log.e("SciChart", "Error while accesing the license", e);
}
setContentView(R.layout.activity_ecgmonitor_fragment);
// Create a SciChartSurface
final SciChartSurface surface = new SciChartSurface(this);
// Get a layout declared in "activity_main.xml" by id
LinearLayout chartLayout = (LinearLayout) findViewById(R.id.chart_layout);
// Add the SciChartSurface to the layout
chartLayout.addView(surface);
// Initialize the SciChartBuilder
SciChartBuilder.init(this);
// Obtain the SciChartBuilder instance
final SciChartBuilder sciChartBuilder = SciChartBuilder.instance();
// Create a numeric X axis
final IAxis xAxis = sciChartBuilder.newNumericAxis()
.withAxisTitle("X Axis Title")
.withVisibleRange(-5, 15)
.build();
// Added in Tutorial #8 - two Y axes
// Create a numeric axis, right-aligned
final IAxis yAxisRight = sciChartBuilder.newNumericAxis()
.withAxisTitle("Primary")
// Assign a unique ID to the axis
.withAxisId("primaryYAxis")
.withAxisAlignment(AxisAlignment.Right)
.build();
// Create another numeric axis, left-aligned
final IAxis yAxisLeft = sciChartBuilder.newNumericAxis()
.withAxisTitle("Secondary")
// Assign a unique ID to the axis
.withAxisId("secondaryYAxis")
.withAxisAlignment(AxisAlignment.Left)
.withGrowBy(0.2,0.2)
.build();
// Add both Y axes to the YAxes collection of the surface
Collections.addAll(surface.getYAxes(), yAxisLeft, yAxisRight);
// Added in Tutorial #3
// Add a bunch of interaction modifiers to a ModifierGroup
ModifierGroup chartModifiers = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withPinchZoomModifier().build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.withZoomExtentsModifier().withReceiveHandledEvents(true).build()
.withXAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Scale).withClipModeX(ClipMode.None).build()
.withYAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Pan).build()
.build();
// Add the X axis to the XAxes collection of the surface
Collections.addAll(surface.getXAxes(), xAxis);
// Add the interactions to the ChartModifiers collection of the surface
Collections.addAll(surface.getChartModifiers(), chartModifiers);
// Added in Tutorial #6 - FIFO (scrolling) series
// Create a couple of DataSeries for numeric (Int, Double) data
// Set FIFO capacity to 500 on DataSeries
final int fifoCapacity = 500;
final XyDataSeries lineData = sciChartBuilder.newXyDataSeries(Integer.class, Double.class)
.withFifoCapacity(fifoCapacity)
.build();
final XyDataSeries scatterData = sciChartBuilder.newXyDataSeries(Integer.class, Double.class)
.withFifoCapacity(fifoCapacity)
.build();
// Create and configure a line series
final IRenderableSeries lineSeries = sciChartBuilder.newLineSeries()
.withDataSeries(lineData)
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withStrokeStyle(ColorUtil.LightBlue, 2f, true)
.build();
// Create an Ellipse PointMarker for the Scatter Series
EllipsePointMarker pointMarker = sciChartBuilder
.newPointMarker(new EllipsePointMarker())
.withFill(ColorUtil.LightBlue)
.withStroke(ColorUtil.Green, 2f)
.withSize(10)
.build();
// Create and configure a scatter series
final IRenderableSeries scatterSeries = sciChartBuilder.newScatterSeries()
.withDataSeries(scatterData)
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withPointMarker(pointMarker)
.build();
// Add a RenderableSeries onto the SciChartSurface
surface.getRenderableSeries().add(scatterSeries);
surface.getRenderableSeries().add(lineSeries);
surface.zoomExtents();
// Added in Tutorial #5
// Create a LegendModifier and configure a chart legend
ModifierGroup legendModifier = sciChartBuilder.newModifierGroup()
.withLegendModifier()
.withOrientation(Orientation.HORIZONTAL)
.withPosition(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 10)
.build()
.build();
// Add the LegendModifier to the SciChartSurface
surface.getChartModifiers().add(legendModifier);
// Create and configure a CursorModifier
ModifierGroup cursorModifier = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withCursorModifier().withShowTooltip(true).build()
.build();
// Add the CursorModifier to the SciChartSurface
surface.getChartModifiers().add(cursorModifier);
// Added in Tutorial #9 - one more SciChartSurface
final SciChartSurface surface2 = new SciChartSurface(this);
// Add the SciChartSurface to the layout
chartLayout.addView(surface2);
// Set layout parameters for both surfaces
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
surface.setLayoutParams(layoutParams);
surface2.setLayoutParams(layoutParams);
// Create a numeric X axis
final IAxis xAxis2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("X Axis Title")
.withVisibleRange(-5, 15)
.build();
// Create a numeric axis
final IAxis yAxisRight2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("Primary")
.withAxisId("primaryYAxis")
.withAxisAlignment(AxisAlignment.Right)
.build();
// Create another numeric axis
final IAxis yAxisLeft2 = sciChartBuilder.newNumericAxis()
.withAxisTitle("Secondary")
.withAxisId("secondaryYAxis")
.withAxisAlignment(AxisAlignment.Left)
.withGrowBy(0.2, 0.2)
.build();
// Add the Y axis to the YAxes collection of the surface
Collections.addAll(surface2.getYAxes(), yAxisLeft2, yAxisRight2);
// Add the X axis to the XAxes collection of the surface
Collections.addAll(surface2.getXAxes(), xAxis2);
// Create and configure an area series
final IRenderableSeries areaSeries = sciChartBuilder.newMountainSeries()
.withDataSeries(scatterData)
.withYAxisId("primaryYAxis")
.withStrokeStyle(ColorUtil.LightBlue, 2f, true)
.withAreaFillColor(ColorUtil.argb(ColorUtil.LightSteelBlue, 0.6f))
.build();
// Add the area series to the RenderableSeries collection of the surface
Collections.addAll(surface2.getRenderableSeries(), areaSeries);
// Create the second collection of chart modifiers
ModifierGroup chartModifiers2 = sciChartBuilder.newModifierGroup()
// Setting MotionEventsGroup
.withMotionEventsGroup("SharedMotionEvents").withReceiveHandledEvents(true)
.withZoomExtentsModifier().withReceiveHandledEvents(true).build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.withPinchZoomModifier().withReceiveHandledEvents(true).build()
.withCursorModifier().withReceiveHandledEvents(true).build()
.build();
// Add the interactions to the ChartModifiers collection of the surface
Collections.addAll(surface2.getChartModifiers(), chartModifiers2);
TimerTask updateDataTask = new TimerTask() {
private int x = 0;
@Override
public void run() {
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
lineData.append(x, Math.sin(x * 0.1));
scatterData.append(x, Math.cos(x * 0.1));
// Added in Tutorial #7
// Add an annotation every 100 data points
if(x%100 == 0) {
TextAnnotation marker = sciChartBuilder.newTextAnnotation()
// Register on a particular Y axis using its ID
.withYAxisId("primaryYAxis")
.withIsEditable(false)
.withText("N")
.withBackgroundColor(ColorUtil.Green)
.withX1(x)
.withY1(0.0)
.withVerticalAnchorPoint(VerticalAnchorPoint.Center)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withFontStyle(20, ColorUtil.White)
.withZIndex(1)
.build();
surface.getAnnotations().add(marker);
// Remove one annotation from the beginning
// in the FIFO way
if(x > fifoCapacity){
surface.getAnnotations().remove(0);
}
}
// Zoom series to fit the viewport
surface.zoomExtents();
surface2.zoomExtents();
++x;
}
});
}
};
Timer timer = new Timer();
long delay = 0;
long interval = 10;
timer.schedule(updateDataTask, delay, interval);
}
}
xml file:
<?xml version="1.0" encoding="utf-8"?>
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/chart"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
- Aditya Kadambi answered 3 years ago
- last edited 3 years ago
- You must login to post comments
Hi there,
I don’t see where you declare and configure SciChartSurface and its parts ( you need at least one X and Y axis for chart to draw something ). Can you provide entire code of project?
Best regards,
Yura
- Yura Khariton answered 3 years ago
-
Hi Yura, I have updated the full source code, did u get a chance to look into ? We are struck Regards, Aditya
-
Hi Yura, Still we have the same issue> Can you please help us
-
Hi Yura, I am able to fix this issue by switching the surface to canvas by adding the below code: surface.setRenderSurface(new RenderSurface(getActivity())); Thanks, Aditya
-
I’m glad that you managed to find workaround. But still that’s interesting and I would like to debug entire project which reproduces this issue to understand why default RenderSurface causes this exception.
- You must login to post comments
Please login first to submit.