diogobernardino / williamchart

Android Library to rapidly develop attractive and insightful charts in android applications.
5.1k stars 800 forks source link

Do not show linechart if layout height too big #45

Open naq219 opened 9 years ago

naq219 commented 9 years ago

i tryed your example , when set height to 300dp, it not work

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/app_background">

    <com.db.chart.view.LineChartView

        xmlns:chart="http://schemas.android.com/apk/res-auto"

        android:layout_height="300dp"
        android:id="@+id/linechart"
        android:layout_width="match_parent"

        android:layout_marginTop="7dp"
        android:layout_marginLeft="7dp"
        android:layout_marginRight="7dp"
        android:layout_marginBottom="2dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:background="#00BBA7"
        chart:chart_axisColor="@color/axis"
        chart:chart_typeface="Roboto-Regular.ttf"
        chart:chart_labelColor="@color/label"
        chart:chart_axisBorderSpacing="0dp">
    </com.db.chart.view.LineChartView>

<com.db.chart.view.BarChartView
    xmlns:chart="http://schemas.android.com/apk/res-auto"
    android:id="@+id/barchart"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".22"
    android:layout_marginTop="2dp"
    android:layout_marginLeft="7dp"
    android:layout_marginRight="7dp"
    android:layout_marginBottom="2dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#F67743"
    chart:chart_axisColor="@color/axis"
    chart:chart_typeface="Roboto-Regular.ttf"
    chart:chart_labelColor="@color/label"
    chart:chart_axisBorderSpacing="25dp"
/>

<com.db.chart.view.HorizontalBarChartView
    xmlns:chart="http://schemas.android.com/apk/res-auto"
    android:id="@+id/horbarchart"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".22"
    android:layout_marginTop="2dp"
    android:layout_marginLeft="7dp"
    android:layout_marginRight="7dp"
    android:layout_marginBottom="2dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#9e9d24"
    chart:chart_axisColor="@color/axis"
    chart:chart_typeface="Roboto-Regular.ttf"
    chart:chart_labelColor="@color/label"
    chart:chart_axisBorderSpacing="25dp"
    />

<com.db.chart.view.StackBarChartView
    xmlns:chart="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stackbarchart"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".22"
    android:layout_marginTop="2dp"
    android:layout_marginLeft="7dp"
    android:layout_marginRight="7dp"
    android:layout_marginBottom="7dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#00BAD3"
    chart:chart_axisColor="@color/axis"
    chart:chart_typeface="Roboto-Regular.ttf"
    chart:chart_labelColor="@color/label"
    chart:chart_axisBorderSpacing="25dp"
/>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".10"
    android:orientation="horizontal" >
    <ImageButton
        android:id="@+id/alpha"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".17"
        android:src="@drawable/alpha"
        android:background="@drawable/button"
        android:contentDescription="@string/alpha_str"/>
    <View android:layout_width=".5dp"
        android:layout_height="match_parent"
        android:background="#1f3133"/>
    <ImageButton
        android:id="@+id/enter"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".17"
        android:src="@drawable/enterb"
        android:background="@drawable/button"
        android:contentDescription="@string/enter_str"/>
    <View android:layout_width=".5dp"
        android:layout_height="match_parent"
        android:background="#1f3133"/>
    <ImageButton
        android:id="@+id/order"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".17"
        android:src="@drawable/ordere"
        android:background="@drawable/button"
        android:contentDescription="@string/order_str"/>
    <View android:layout_width=".5dp"
        android:layout_height="match_parent"
        android:background="#1f3133"/>
    <ImageButton
        android:id="@+id/ease"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".17"
        android:src="@drawable/ease_cubic"
        android:background="@drawable/button"
        android:contentDescription="@string/ease_str"/>
    <View android:layout_width=".5dp"
        android:layout_height="match_parent"
        android:background="#1f3133"/>
    <ImageButton
        android:id="@+id/play"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".30"
        android:src="@drawable/play"
        android:background="@color/button_hey"
        android:contentDescription="@string/play_str"/>
</LinearLayout>

diogobernardino commented 9 years ago

If you want to make LineChartView bigger in the sample application you better increase the weight of LineChartView. Otherwise to use dp I would recommend you to define your own layout. I can assure you that it works.

alisherafat01 commented 8 years ago

Same issue here... what do you mean by define your own layout if you want to use dp? this is my layout file:

` <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true"

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <com.db.chart.view.LineChartView
                android:id="@+id/chart1"
                android:layout_width="1000dp"
                android:layout_height="300dp"
                android:layout_marginBottom="15dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"/>
        </LinearLayout>
    </HorizontalScrollView>`
diogobernardino commented 8 years ago

By defining his own layout I simply meant not copy pasting the sample application and expect it to work as he wanted, without understanding the layout itself.

Can you edit your message, I think something went wrong when you posted the code of or layout?

alisherafat01 commented 8 years ago

i don't know why the editor can not format my code snippet.... that is just a HorizontalScrollView actually layout height for chart view does not work with all values . chart disappears when i set layout_height="300dp" but works when i use 200dp!

diogobernardino commented 8 years ago

I looked into the problem but unfortunately I still cannot understand why is it happening. What I could observe so far is that theonDrawmethod doesn't get called if values too big are defined for height or width. Checking the size of the view in onMeasure everything seems nominal. Also onPreDrawListener gets called and with a proper view size. For instance, in my tests, defining the values width="996dp" and height="171dp" the chart is displayed without problems, increasing the width in 1dp (997dp) it's not anymore displayed. A few more bits of information can be found in #152 . All in all, for the time being I still can't point out the root cause.

lukcz commented 7 years ago

Does it occur when chart lies inside ScrollView? How about http://stackoverflow.com/questions/34374363/behavior-of-setwillnotdrawfalse ?? Maybe that's the root cause?

diogobernardino commented 7 years ago

Don't think so, I have it under onAttachedToWindow. But anyway, I can give it a try moving it into the constructor, not sure it will make any difference.

diogobernardino commented 7 years ago

It didn't do the trick. :/

charlag commented 7 years ago

I've found the problem "BarChartView not displayed because it is too large to fit into a software layer (or drawing cache), needs 15913800 bytes, only 8294400 available" Not sure how to solve it. Looks like scrolling should be baked into the chart itself.

diogobernardino commented 7 years ago

Thanks for sharing. I also think this should be the case, but I haven't had the time to look into it. Maybe someone from the thread can contribute.

charlag commented 7 years ago

@diogobernardino I temporarily solved this by setting android:layerType="software" on the ScrollView. Animations may be not as smooth, tho, so it's only a workaround

fabiancrx commented 4 years ago

This issue persists in v3 of the library.