Extract Object Data from the column
Hi,
My data is in an Object in a column. I want to use that data to showcase in the Line chart. Currently I am using compose SDK to create a Line chart. Could anyone can help me to extract that data?
Column looks like this: {"sales": [1570.73, 1020.58]}. Want to extract the sales data.
amitpatil
Posted 1 year ago·Last reply 1 year ago
6 comments
DRay
·1 year agoHello @amitpatil,
I’m following up to see if the solutions offered by @AssafHanina or bogdan-karlenko worked for you.
If so, please click the 'Accept as Solution' button on the appropriate post. That way other users with the same questions can find the answer. If not, please let us know so that we can continue to help.
Thank you.
DRay
·1 year agoHello amitpatil,
I’m following up to see if the solutions offered by AssafHanina or AssafHanina worked for you.
If so, please click the 'Accept as Solution' button on the appropriate post. That way other users with the same questions can find the answer. If not, please let us know so that we can continue to help.
Thank you.
Assaf Hanina
·1 year agoHey amitpatil ,
If the data is being pulled directly into the Sisense ElastiCube, you can apply the transformation using the Custom Code feature.
Custom Code Feature allows you to run a Jupyter notebook during the build process to transform the data, such as modifying the Object column, and return a DataFrame that can then be used in a Line Chart.
Best regards
DRay
·1 year agoHi amitpatil,
I want to let you know about the Office Hours that is happening today at 2pm Eastern, 7pm UTC. Team Lead of Software Engineering Jeremy F. will be live for one hour in Discord to answer your Sisense and CSDK questions! Click here to join: https://discord.gg/bzqv8eCvJb
Hope to see you there!
bogdan-karlenko
·1 year ago · EditedHi amitpatil, thanks for your question!
Based on the format of your data, it looks like you're not querying directly from a Sisense instance but using an external data source instead. In that case, you'll need to ensure your data is structured appropriately for the Line chart component.
Here’s a simple example, assuming you’d like to build a double Line chart (since you have two values per data point) plotted over time:
You can use standard JavaScript methods to extract and manipulate data from objects and arrays. Since your column contains objects like `{"sales": [1570.73, 1020.58]}`, you can access the sales data using something like `row.sales` (assuming each row is an object). You might want to look into `map()` to transform your dataset into the required format.
Hope this helps!
amitpatil
OP1 year agoThank you for the response bogdan-karlenko.
I am using compose SDK to embed the Line chart in my application. I connected the DB to Sisense and from the Sisense I am using following command to generate the data model representation of the table.
npx @sisense/sdk-cli@latest get-data-model --username "<username>" --output src/sample-ecommerce.ts --dataSource "Sample ECommerce" --url <your_instance_url>
Using this data model to plot the Line chart like this
<SisenseContextProvider
url="<instance url>" // replace with the URL of your Sisense instance
token="<api token>" // replace with the API token of your user account
>
<Chart
dataSet={DM.DataSource}
chartType={'line'}
dataOptions={{
category: [DM.Commerce.AgeRange],
value: [measureFactory.sum(DM.Commerce.Revenue)],
breakBy: [],
}}
styleOptions={{
legend: {
enabled: true,
position: 'bottom',
},
}}
onDataPointClick={(point, nativeEvent) => {
console.log('clicked', point, nativeEvent);
}}
/>
</SisenseContextProvide
As my data is in an Object {sale:[123,1212,232, 564]}. It is not working properly. So I just want to know is there any way we can extract the data from the generated Data Model?