score:0
Not sure if this applies, but Postgres provides a lot of tools for formatting data before the return. For example, here's a simple example based on a table called "mockit" that I've got some sample data in:
SELECT row_to_json(mockit_row) AS mockit_objects
FROM
(SELECT first_name, last_name, email
FROM mockit
WHERE gender = 'Male'
LIMIT 10) AS mockit_row;
What you get is one object per row, as a JSON object
{"first_name":"Farlay","last_name":"Creegan","email":"fcreegan0@github.io"}
{"first_name":"Holt","last_name":"Cicco","email":"hcicco1@scribd.com"}
etc.
If you want a single JSON object with an array of objects:
SELECT array_to_json(array_agg(row_to_json(mockit_row))) AS mockit_objects
FROM
(SELECT first_name, last_name, email
FROM mockit
WHERE gender = 'Male'
LIMIT 10) AS mockit_row;
D3 (I miss working with D3) dehydrates things into arrays of objects, as I recall. So you can provide the data in the format, if it's easier. CSV and TSV are smaller wire formats, but I don't think (?) there's currently support for output results to that format within Postgres as a SQL call.
Postgres is crazy fast, so it's good to push processing up to it.
score:1
Solved it myself, basically what I did was in views.py
return JsonResponse(serializers.serialize('json', myData), safe=False)
Where myData = (model).objects.all()
Then all I had to do was parse the data in javascript.
Source: stackoverflow.com
Related Query
- How do I import a PostgreSQL table into d3 for use?
- How to generate "fake" rows in PostgreSQL to use for d3.js
- How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
- how to use svg file for image source in D3
- How to import a d3 v4 / v5 module into a Node project but keep the D3 v3 namespace style (d3.)?
- How can I connect two parent node into one child node and how to make a tooltip for each node in the tree pragmatically? in D3 js (SVG)
- D3: How to use exit().remove() for Multi-Series Line Chart
- How to combine two d3 objects into one for bulk operations
- How would I import a single column CSV file into a pie chart using Javascript D3?
- How to use D3.format for dynamic values having different numbers?
- How to use the useRef hook for setNativeProps in React Native?
- D3.js - How to use different styles for tick labels in one plot?
- How to save d3 selections in an array for later use D3.js?
- How to make D3.js use UTC times for the x-axis, with Moment.js
- How do I import the D3 library into my project file structure?
- I am trying to use multiple 2 arrays for binding data for svg circles but cannot figure out how
- How to use series.stack = false in dimple.js to suppress aggregation; different symbols for each series
- When creating an HTML table with D3, use certain data for a row class rather than cell
- In Angular app, how do I import d3 and use d3.js scripts?
- How to convert table data to nodes and links for d3js Sankey
- D3: how to use the update pattern for on-click-text?
- How would I be able to convert table structured data to a dict/graph structure in python/pandas, to be used for force graphs in D3?
- How to convert my data into a format suitable for d3.js sunburst?
- How do I use mouseover for an element hidden behind an invisible element?
- How to import the d3.js v5 module into a polymer 3 element?
- D3.js - How to use inline JSON as dataset for D3 charts, instead of csv/tsv/json file
- How to use D3 to load csv, display table and style it with bootstrap in javascript
- How to use d3.force for dynamic, non-overlapping labeling of a scatterplot
- Sankey Diagram (D3) - How to use multiple units for link values and how to add notes to mouseover popup box?
- How to interpolate or get color for the point/values not in specified color table range
More Query from same tag
- nvd3: How highlight whole stacked bar on mouseover?
- Need d3.js logic to work on JSON data
- D3.js nodes not appearing on page load
- Why is there a triangle missing from the return value of d3.voronoi.triangles?
- D3: dom elements appended to the unexpected parent nodes
- x axis ticks not appearing in d3
- Why isnt `d` defined in d3.behavior.drag()
- NVD3 Stacked Bar Chart Plus Line Overlapped
- d3.js dynamically create brush functions
- How to add an event listener to entire window except for a defined donut (or annulus)
- Why doesn't my pie chart update with the new size?
- Color fill in D3 gives error in If Loop
- d3.js pan restricted behaviour
- Fill D3.js rect with multiple colors or split rect into multiple rects
- D3 Angular Tree
- Sunburst incomplete Segments
- D3 js legend for a dynamic dataset
- D3.js time scale quirk with "11 PM" values
- Drawing a line with two different colors using D3
- Add additional fields in angular-nvd3 tooltip
- Data joins with d3.stack.layout()
- dc.js multiple select menu with checkboxes
- D3js change ticks x and y axis
- Generate D3 graphics inside Databricks notebook with scala usign RDD data
- Failing to transition in D3 off new data
- internal link for using lightbox (fancyBox) in a d3 script
- d3.js categorical time series (evolustrip)
- Isolating scope for multiple d3 components in AngularJS directives within ng-repeat
- transition of x-axis results in overflow
- Using dc.js on nested JSON to create bar chart