Comments (4)
I'm not sure I understand what your current issue is. Could you provide some examples of the data youre giving to django-graphos and what is being returned?
The steps I take to pass datetime to django-graphos using Google looks something like this in my views:
queryset_black_levels = combined_black_levels.order_by('toner_date')[:180]
if len(queryset_black_levels) > 0:
haxis_labels = int(len(queryset_black_levels) / 4)
for item in queryset_black_levels:
item.toner_date = datetime.date(item.toner_date)
item.toner_date = item.toner_date.isoformat()
The key is to convert to isoformat. You may also find my chart settings helpful:
chart_black = gchart.LineChart(data_source_black_levels, options={'title': 'Black Levels', 'chartArea': {'width': '75%', 'height': '60%'}, 'legend': { 'position': 'none' }, 'vAxis': { 'format': 'percent', 'viewWindowMode': 'explicit', 'viewWindow': { 'max': 1, 'min': 0}}, 'colors': ['#000000'], 'hAxis': {'format': 'M/d/yy', 'gridlines': {'count': 5}, 'showTextEvery': haxis_labels}}, height=150, width='100%')```
from django-graphos.
@recordnotfound Ultimately we need to send this data to frontend and so need to serialize this. So you need to convert your data to something which could be serialized.
You need to override get_data() of existing DataSource and convert datetime field into something which could be serialized.
Assuming you are using a Python list as data, then you need to do:
class MySimpleDataSource(SimpleDataSource):
def get_data(self):
data = super(MySimpleDataSource, self).get_data()
header = data[0]
data_without_header = data[1:]
for row in data_without_header:
# Assuming first column contains datetime
row[0] = row[0].year
data_without_header.insert(0, header)
return data_without_header
And data has
d1 = datetime(2015, 7, 8, 1, 1)
d2 = datetime(2016, 7, 8, 3, 1)
data1 = [
['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],
[d1, 1000, 400, 100, 600],
[d2, 1170, 460, 120, 310],
]
chart = flot.LineChart(MySimpleDataSource(data=data1))
If you are planning to use queryset with ModelDataSource, then you would create following class
class MyModelDataSource(ModelDataSource):
def get_data(self):
data = super(MyModelDataSource, self).get_data()
header = data[0]
data_without_header = data[1:]
for row in data_without_header:
# Assuming second column contains datetime
row[1] = row[1].year
data_without_header.insert(0, header)
return data_without_header
And you would use this class like:
queryset = Account.objects.all()
chart = flot.LineChart(MyModelDataSource(queryset=queryset, fields=['sales', 'datetime_field','expenses']))
from django-graphos.
@recordnotfound It should be doable with the code snippets mentioned in last comment, so closing this ticket. Feel free to open this again if you need further help.
from django-graphos.
In the workaround, @akshar-raaj gets the year, which is serializable, but @recordnotfound asked about a datetime field. I have the same issue using date values. I've tried to replace row[0] = row[0].year
with row[0] = row[0].date()
, but that returns dates as strings, which JavaScript doesn't recognize as dates. How would you return serializable dates or datetimes?
from django-graphos.
Related Issues (20)
- Morris Donut not supporting colors option?
- Demo page gives 500 error
- Dygraphs support
- Chart does not load when table update instead of page refresh
- Related WebPage may have Typo
- highchart tooltip useHTML does not work
- Issue with GoogleCharts and counting unique values HOT 1
- Setting Chart size to width of page? HOT 1
- Display chart inside javascript
- Add ability to pass links in gcharts
- C3.js renderer lacks support for area charts and stacking
- Demo page yields "404" error HOT 4
- maximum recursion depth exceeded on LineChart
- Issue on annotation?
- Docs and demo are down HOT 2
- This doesn't appear to work anymore with Google HOT 2
- Is this project still maintained?? HOT 1
- This project needs a maintainer.
- Bug in documentation HOT 1
- Documentation Error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-graphos.