Build Your own Pie Chart with Jetpack Compose in Android - Android Studio Tutorial | Canvas

In this video I will show you how you can create a custom Pie Chart in Android with Jetpack Compose drawing on Canvas. The Pie Chart will be also clickable to show different information and expand the Pie Charts elements.
Get the final source code here:
github.com/MatthiasKerat/PieC...

Пікірлер: 29

  • @murderousgod-pubglite4262
    @murderousgod-pubglite4262 Жыл бұрын

    Woaah you really did it, Thanks that was amazing.

  • @SiamakAshrafi
    @SiamakAshrafi Жыл бұрын

    R U kidding me. This is amazing. You should have 70K subscribers not 70 ... Just wrote a medium article explaining how we are using this in our sleep tacking app. Linking back to your video to help promote the channel.

  • @SurayyoUZB
    @SurayyoUZB10 ай бұрын

    Thank you for this video. This video is so good and great. This video really helps me to create Pie Chart in compose. I recommend you to watch it

  • @mesutemrecelenk5447
    @mesutemrecelenk5447 Жыл бұрын

    Thanks a lot bro.

  • @sandrastojanovic1849
    @sandrastojanovic184911 ай бұрын

    Congratulations, this is awesome! I watched the other video with Circular Progress Indicator, and it is awesome as well! Thank you for sharing this! Have you tried to combined those two, drag gestures with Pie Chart, where you can drag every piece of Pie Chart in order to change the percentage of each part manually?

  • @ramakanaparthy1953
    @ramakanaparthy1953 Жыл бұрын

    This is great, l have to create something similar to this.

  • @ramakanaparthy1953
    @ramakanaparthy1953 Жыл бұрын

    How to add the selected part to the outside with the same width and colour should be transparent to selected part?

  • @jumps63
    @jumps63 Жыл бұрын

    Hi, How can I know what is height of this composable in db? If I remove fillMaxSize() property from Canvas and place PieChart between two composables it will overlap eachother. Do you have any tips for that?

  • @kapps7407

    @kapps7407

    Жыл бұрын

    You should always pass a modifier to the canvas which defines the height. You can also pass a relative height or if you want a fixed one. The exact dp can then be accessed inside the Canvas with the size property. If you need this height outside of your Canvas you can pass a lambda function and pass the height in there and collect the value from the outside

  • @jumps63

    @jumps63

    Жыл бұрын

    @@kapps7407 I need exact dp outside of canvas composable. I know i can access size value, but that gives value in float value, not in dp if I am correct?

  • @kapps7407

    @kapps7407

    Жыл бұрын

    You can convert this float value which are actually pixels to dp then :)

  • @ramakanaparthy1953
    @ramakanaparthy1953 Жыл бұрын

    Source code please

  • @hanadanefa7837
    @hanadanefa7837 Жыл бұрын

    may I know your device your currently using? I mean what specs your device have

  • @kapps7407

    @kapps7407

    Жыл бұрын

    This emulator is a Google Pixel 4XL if I remember correctly

  • @hanadanefa7837

    @hanadanefa7837

    Жыл бұрын

    @@kapps7407 I mean your laptop or pc that you use for development :)

  • @kapps7407

    @kapps7407

    Жыл бұрын

    Oh okay - It is a 27 inch iMac 2020 with an i7 processor and 64gb RAM

  • @hanadanefa7837

    @hanadanefa7837

    Жыл бұрын

    Thank you

  • @leonidas_30052
    @leonidas_30052 Жыл бұрын

    First of all my congratulations and thanks, you are really good at what you do. I was trying to feed this graph with the Room database but I get an error on the line "if (inputList.first().isTapped)" I'm racking my brain to solve it rsrs

  • @kapps7407

    @kapps7407

    Жыл бұрын

    Hello Daniel, thank you! What error do you get? Maybe the input list is empty so there is no first element and you are trying to access it. If Room takes some amount of time and your list is empty at the beginning when you invoke the composable the first time this could happen. But to give you an exact hint I need more information.

  • @leonidas_30052

    @leonidas_30052

    Жыл бұрын

    @@kapps7407 that's exactly it, the first time compose draws the screen, the list is empty and the "isTapped" property is false, where the error happens. I used "firstOrNull" or instead of just "first", but even so, the layout doesn't recompose and doesn't fetch the data in the database, and it doesn't feed the graph. I'm trying to see what I can do, but still nothing =/

  • @kapps7407

    @kapps7407

    Жыл бұрын

    You should make your input list state which then triggers the recomposition (For example in a view model). Then when the Room result is there you can map the result to the InputList and update your list. This should trigger the recomposition. For the first case when the list is empty by default you could for example make an if statement inside the chart composable and show the chart when list.size>0 and otherwise show a placeholder text with "Currently no data available" or something like this.

  • @leonidas_30052

    @leonidas_30052

    Жыл бұрын

    @@kapps7407 Yes, I'm using the viewModel, and I even check it. I have a state class that contains " val isEmpty: Boolean", when collecting the list I check if it is empty and depending on the condition, true or false, I assign it to this property. I can't understand why compose doesn't recompose itself. I made an if in the "inputList" if it is greater than 0 or not, and I put a text if it is less, saying that there is no data, however, it stays there, it doesn't recompose itself, I'm almost there, I just need to know why it it is not recovering.

  • @kapps7407

    @kapps7407

    Жыл бұрын

    How does your state list (The list For the Piechart) look and how do you update it when there is a Room result? I am pretty sure there is just a little problem with updating the state properly.

Келесі