Draw ChartView on SurfaceView


Creating ChartView, configuring it and adding it to layout works fine, however drawing same chart onto SurfaceView doesn’t fully work.

For example code below results in graph being partially drawn onto SurfaceView, labels, lines, background and etc. drawn correctly, but graph is missing actual lines from LineSeries.

Note that labels are drawn in correct range for data in DataAdapter.

public void surfaceCreated(final SurfaceHolder holder) {
//chart creation
    Canvas canvas = holder.lockCanvas(null);
    if (canvas != null) {
        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        chartView.measure(widthSpec, heightSpec);
        chartView.layout(0, 0, width, height);

Is it possible to draw ChartView on SurfaceView?
What am I missing here to render LineSeries (adding to layout renders fine)?


Hi azemar,
From what you have said it would suggest that your chart’s plot area is not rendering. A ChartView is a ViewGroup, comprising of several Views as layers, with the plot area being held within one of those layers. The plot area itself will be either a SurfaceView or TextureView depending upon the API level of the device on which it runs. The reason for this is that we render our plot area using openGL.
We have never actually tried to achieve what you are doing with your chart but I would suggest you look into the implications of placing a SurfaceView (or TextureView, as appropriate) on top of a SurfaceView. You may find that some prerequisite step is needed to achieve this.
I did however notice when looking at the API docs for TextureVew the following comment for the onDraw method:

 * Subclasses of TextureView cannot do their own rendering
 * with the {@link Canvas} object.
 * @param canvas The Canvas to which the View is rendered.

Looking at this it may not actually be possible for our openGL rendering to be performed in such a way.
Please let us know how you get on.