Rendering JSON data in a SfCartesianChart

hello,


I have the following JSON data and would like to display separate lines on the chart for both the actual and plan values.

[
{
"Year": 2018.0,
"Quarter": 1.0,
"Target": 10,
"Actual": 20
},
{
"Year": 2018.0,
"Quarter": 2.0,
"Target": 10,
"Actual": ""
},
{
"Year": 2018.0,
"Quarter": 3.0,
"Target": 30,
"Actual": ""
},
{
"Year": 2018.0,
"Quarter": 4.0,
"Target": 40,
"Actual": ""
},
{
"Year": 2019.0,
"Quarter": 1.0,
"Target": 50,
"Actual": ""
},
{
"Year": 2019.0,
"Quarter": 2.0,
"Target": 50,
"Actual": ""
},
{
"Year": 2019.0,
"Quarter": 3.0,
"Target": 50,
"Actual": 40
},
{
"Year": 2019.0,
"Quarter": 4.0,
"Target": 50,
"Actual": 45
},
{
"Year": 2020.0,
"Quarter": 1.0,
"Target": 50,
"Actual": 47
},
{
"Year": 2020.0,
"Quarter": 2.0,
"Target": 60,
"Actual": 55
},
{
"Year": 2020.0,
"Quarter": 3.0,
"Target": 60,
"Actual": 56
},
{
"Year": 2020.0,
"Quarter": 4.0,
"Target": 90,
"Actual": 80
},
{
"Year": 2021.0,
"Quarter": 1.0,
"Target": 90,
"Actual": 88
},
{
"Year": 2021.0,
"Quarter": 2.0,
"Target": 100,
"Actual": ""
},
{
"Year": 2021.0,
"Quarter": 3.0,
"Target": 100,
"Actual": 99
},
{
"Year": 2021.0,
"Quarter": 4.0,
"Target": 100,
"Actual": 98
}
]


I also would like to modify the chart based on an 'onPressed' command that the user can press.

Q1 --> display the values for the first quarter of the last year (In this case, 2021).


Q2 --> display the values for the second quarter of the last year (In this case, 2021).

 


Q3 --> display the values for the third quarter of the last year (In this case, 2021).

 


1Yr --> display the values for the last year; Q1, Q2, Q3, and Q4 (In this case, 2021).

3Yr --> display the values for the last three years (in this case, 2019, 2020, and 2021).

MAX --> display the values for the last years (in this case, 2018, 2019, 2020, and 2021).



13 Replies

SK Sriram Kiran Senthilkumar Syncfusion Team August 30, 2022 02:14 PM UTC

Hi Sara,


Greetings from Syncfusion.

We have checked your query at our end, and we have created a simple sample with the provided JSON structure in which we have rendered the chart by serializing the Json data structure and as per your requirement, placed six buttons with which you can be able to change the chart data in the chart. We have also attached the sample below for reference. Please check and get back to us if you require further assistance.


Regards,

Sriram Kiran


Attachment: f177107_629c9fb6.zip


SA Sara Alruwais September 4, 2022 10:00 AM UTC

hello!

 thank you so much!


can the '1Yr'  button be selected by default when I first load the page? and you can view the values for '1Yr'



SK Sriram Kiran Senthilkumar Syncfusion Team September 5, 2022 07:06 AM UTC

Hi Sara,


We have checked your query at our end and modified the previously provided sample as per your requirement and attached it below for reference.

Please check and get back to us if you require further assistance


Regards,

Sriram Kiran


Attachment: f177107_a6320dad.zip


SA Sara Alruwais September 5, 2022 11:43 AM UTC

Thank you Sriram for you help! 


I just have a further question. Is it possible to make the class you created reusable?

meaning, I use it again for a different file, the only line of code I would change is the json file to display different data on the chart.



SK Sriram Kiran Senthilkumar Syncfusion Team September 6, 2022 09:42 AM UTC

Hi Sara,


Yes, it is possible to reuse the model class created for the JSON parsing only if that JSON data structure and the fields in it are not changed or modified and only the data values will be changed for the chart. Please check and get back to us if you require further assistance.


Regards,

Sriram Kiran



SA Sara Alruwais September 6, 2022 12:13 PM UTC

that's great! would it be possible to assist me on that Siriam?



SK Sriram Kiran Senthilkumar Syncfusion Team September 7, 2022 11:54 AM UTC

Hi Sara,


We kindly request you to share with us the JSON data structure in the JSON file, which you will replace in the code so that it will help us check whether the class model created currently can be reused for that JSON data structure or not.


Regards,

Sriram Kiran



SA Sara Alruwais September 8, 2022 12:09 PM UTC

[
{
"Year": 2018.0,
"Quarter": 1.0,
"Target": "",
"Actual": 0.20
},
{
"Year": 2018.0,
"Quarter": 2.0,
"Target": "",
"Actual": 0.01
},
{

"Year": 2018.0,
"Quarter": 3.0,
"Target": "",
"Actual": 0.02
},
{

"Year": 2018.0,
"Quarter": 4.0,
"Target": "",
"Actual": 0.03
},
{

"Year": 2019.0,
"Quarter": 1.0,
"Target": 0.19,
"Actual": 0.022
},
{

"Year": 2019.0,
"Quarter": 2.0,
"Target": 0.17,
"Actual": 0.03
},
{

"Year": 2019.0,
"Quarter": 3.0,
"Target": 0.56,
"Actual": 0.09
},
{

"Year": 2019.0,
"Quarter": 4.0,
"Target": 0.15,
"Actual": 0.019
},
{

"Year": 2020.0,
"Quarter": 1.0,
"Target": 0.054,
"Actual": ""
},
{

"Year": 2020.0,
"Quarter": 2.0,
"Target": 0.087,
"Actual": ""
},
{

"Year": 2020.0,
"Quarter": 3.0,
"Target": 0.077,
"Actual": 0.001
},
{

"Year": 2020.0,
"Quarter": 4.0,
"Target": 0.037,
"Actual": 0.007
},
{

"Year": 2021.0,
"Quarter": 1.0,
"Target": 0.099,
"Actual": ""
},
{

"Year": 2021.0,
"Quarter": 2.0,
"Target": 0.043,
"Actual": 0.1
},
{

"Year": 2021.0,
"Quarter": 3.0,
"Target": 0.045,
"Actual": ""
},
{

"Year": 2021.0,
"Quarter": 4.0,
"Target": 0.022,
"Actual": 0.016
}
]


SK Sriram Kiran Senthilkumar Syncfusion Team September 9, 2022 01:59 PM UTC

Hi Sara,


Thanks for the revert. We have checked the provided JSON data structure and we have modified the previously provided sample by loading the latest provided JSON data structure and rendered the chart by reusing the same class model. We have attached the sample below for reference.

Please check and get back to us if you require further assistance.


Regards,

Sriram Kiran


Attachment: f177107_1_eb88382f.zip


SA Sara Alruwais September 12, 2022 10:42 AM UTC

is there a way to create two files (one for each chart) that use the same class? 


in such a way that If I wanted to modify the Sfcartesianchart widget, the changes will apply to the rest of the files dynamically. 



SK Sriram Kiran Senthilkumar Syncfusion Team September 13, 2022 02:17 PM UTC

Hi Sara,


We have analyzed your query at our end, and we are sorry that we are not able to understand what requirement you are proposing in your query as you have told that you have to create two files for each chart widget that uses same class and here we are not sure what class both of them must use and based on the second query we suspect that when you change the chart widget in one file then it must apply those changes in the second file too but we are not sure on what you will be changing in the chart widget.

So, we kindly request you to share with us more information in detail on your requirement with example screenshots or screen recordings so that it will help us assist you in a better way.


Regards,
Sriram Kiran



SA Sara Alruwais September 28, 2022 07:18 AM UTC

thank you for waiting. and i'm sorry for the late reply.


i will try to compile what I need help in this reply. hope it will make things clear!


i have a home page that contains a grid of buttons each one will navigate to a different screen,


when i click on button 1 , i get the below screen (the one on the left). a grid of buttons each containing a unique value name and percentage. when i click on value 1, i will go the the below screen (the one on the right) (the same one you helped me with earlier). also, value 1, value 2, value 3, value 4, value 5 buttons should all navigate to the same screen (the one on the right) but each one has a different json file; so the fusion chart values will change dynamically. the page structure will be exactly the same in all value buttons.


also, the second button in the  bottom navigation bar should have this expandable tile list with the same buttons in the homepage screen, if i expand one, i should get the same value buttons to be added dynamically. so. if I add a new value button in the home screen , it should be added here too. and if I delete one it should be deleted from here too.  

hope this makes sense. thank you again !



SK Sriram Kiran Senthilkumar Syncfusion Team September 29, 2022 01:02 PM UTC

Hi Sara,


Thanks for the revert. We have checked your query at our end, and we have created a simple sample similar to your application and in the main page we have placed two buttons and on clicking them will navigate to the next page which contains two value buttons and on clicking the first value button, the chart rendered with the chart data retrieved from the first JSON file and for the second value button, the chart gets rendered with chart data retrieved from the second JSON file.

For the second page in the navigation bar, you can use the same `ValuePageWidget` to render the value buttons accordingly in the respective expanding tile for the button values as per your requirement.

We have attached the sample below for reference. Please check with the sample and get back to us if you require further assistance.


Regards,
Sriram Kiran


Attachment: f177107_2_5e06bbd8.zip

Loader.
Up arrow icon