i am trying to render a 3d pie chart with chartit_django. i am on Django 1.6.
my code in views.py :
def sales_pie_chart(request):
ds = DataPool(
series=[
{
'options': {
'source': Sale.objects.values('sales_client__client_name').annotate(
sales_total_quantity=Sum('sales_total_quantity'))},
'terms': [
'sales_client__client_name', 'sales_total_quantity'
]
}
]
)
cht = Chart(
datasource=ds,
series_options=[
{
'options': {
'type': 'pie', 'stacking': False,
'options3d': {'enabled': True, 'alpha': 45, 'beta': 0}
}, 'terms': {'sales_client__client_name': ['sales_total_quantity']}
}
],
chart_options={
'title': {'text': 'Sales Report - Pie Chart'}
}
)
return render(request, 'accounting/charts.html', {'cht': cht})
i am betting on the 'options3d' setting but cant seem to find any documentation online.
this code would only give a flat pie chart.
Related
I've got 2 CKEditor5Fields in one of my models. I'm running into an issue in the admin panel that when the browser is in dark mode the background color of the field is staying white and the font color is changing to an off-white color making it really hard to read. The text is fine when it's rendered to the page. Is there a way to set the default font color to black so browser mode doesn't matter?
Light Mode:
Dark Mode :
Model properties:
property_short_description = CKEditor5Field('property short description', config_name='extends', blank = True, null = True)
description = CKEditor5Field('description', config_name='extends')
My config:
CKEDITOR_5_CONFIGS = {
'default': {
'toolbar': ['heading', '|', 'bold', 'italic', 'link',
'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],
},
'extends': {
'blockToolbar': [
'paragraph', 'heading1', 'heading2', 'heading3',
'|',
'bulletedList', 'numberedList',
'|',
'blockQuote', 'imageUpload'
],
'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
'code','subscript', 'superscript', 'highlight', '|', 'codeBlock',
'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|',
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
'insertTable',],
'image': {
'toolbar': ['imageTextAlternative', 'imageTitle', '|', 'imageStyle:alignLeft', 'imageStyle:full',
'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],
'styles': [
'full',
'side',
'alignLeft',
'alignRight',
'alignCenter',]
},
'table': {
'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
'tableProperties', 'tableCellProperties' ],
'tableProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
},
'tableCellProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
}
},
'heading' : {
'options': [
{ 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
{ 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
{ 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
{ 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
]
}
}
}
Django dark mode styles are applied to the CKEditor text color. A possible solution is to use a custom CSS file. Here is my approach:
in the settings.py make sure you have these lines:
# path to the custom CSS file
CKEDITOR_5_CUSTOM_CSS = 'css/ckeditor5/admin_dark_mode_fix.css'
# I don't know why but if I put the CSS file in the STATIC_ROOT folder, the styles are not applied.
# So I use a custom static folder
STATICFILES_DIRS = [
BASE_DIR / 'staticfiles',
]
Then create this CSS file in the root of the project:
staticfiles\css\ckeditor5\admin_dark_mode_fix.css
And add this fix:
.ck.ck-editor {
color: black !important;
}
I am able to get a dictionary from my request function. Here's what I get:
{
'collaborative': False,
'external_urls': {
'spotify': 'http://open.spotify.com/user/dashrif/playlist/3LEoetnegEv2Q8jdmB8TER'
},
'href': 'https://api.spotify.com/v1/users/dashrif/playlists/3LEoetnegEv2Q8jdmB8TER',
'id': '3LEoetnegEv2Q8jdmB8TER',
'images': [{
'height': 640,
'url': 'https://mosaic.scdn.co/640/0cd0508f78c5e5f6e2b01b3009753083c7977270527f35929eff151f80bcabec17b2fb9383da342b32d7d3432ff965abb01f706ec2efc38282a11b45d088e352f19eebb53874fcdc4366ff4249da45fe',
'width': 640
},
{
'height': 300,
'url': 'https://mosaic.scdn.co/300/0cd0508f78c5e5f6e2b01b3009753083c7977270527f35929eff151f80bcabec17b2fb9383da342b32d7d3432ff965abb01f706ec2efc38282a11b45d088e352f19eebb53874fcdc4366ff4249da45fe',
'width': 300
},
{
'height': 60,
'url': 'https://mosaic.scdn.co/60/0cd0508f78c5e5f6e2b01b3009753083c7977270527f35929eff151f80bcabec17b2fb9383da342b32d7d3432ff965abb01f706ec2efc38282a11b45d088e352f19eebb53874fcdc4366ff4249da45fe',
'width': 60
}],
'name': 'Life Playlist Vol. I: The Fuck You Getting Hype For? You Still Broke',
'owner': {
'external_urls': {
'spotify': 'http://open.spotify.com/user/dashrif'
},
'href': 'https://api.spotify.com/v1/users/dashrif',
'id': 'dashrif',
'type': 'user',
'uri': 'spotify:user:dashrif'
},
'public': True,
'snapshot_id': 'PCG8b/CxCfaCjX0mmFMZ3T9NUsJC1sz5MVAXfQf3aefQhcAi4Zdm2k+3rySb/HLw',
'tracks': {
'href': 'https://api.spotify.com/v1/users/dashrif/playlists/3LEoetnegEv2Q8jdmB8TER/tracks',
'total': 63
},
'type': 'playlist',
'uri': 'spotify:user:dashrif:playlist:3LEoetnegEv2Q8jdmB8TER'
}
At least I hope this is a dictionary. Honestly at this point I've gotten so many errors I'm not too sure. Here's the code in question:
playlist_api_endpoint = "{}/playlists".format(profile_data["href"])
playlists_response = requests.get(playlist_api_endpoint,
headers=authorization_header)
playlist_data = json.loads(playlists_response.text)
display_arr = [profile_data] + playlist_data["items"]
return render_template("index.html",sorted_array=display_arr)
Basically I want to be able to filter out the last uri object and any other uri objects when adding new playlists. I've tried .items(), filtered dictionary, and a couple of other things I can't remember. If anyone has an idea of where I'm going wrong or how to to achieve my goal, I'd love some help. Thanks!
I get different results in the displayed chart when I use the highcharts option "chart" in chart_options. Example 1 will display the subtitle but not the background color. Example 2 will show the background color but not the subtitle. Anyone else encountered this behavior?
Python v2.7.5
Django v1.10
django-chartit v0.2.7
django-highcharts v0.1.7
Example 1: displays subtitle, not backgroundColor
#Create the PivotChart object
site_prod_pivotcht = PivotChart(
datasource = site_prod_ds,
series_options = [
{'options':{
'type': 'column',
'stacking': False},
'terms': [
'prod_value',
'wx_adj_value']}
],
chart_options =
{'title': {
'text': 'Actual versus Wx Adjusted Production Data'},
'subtitle': {
'text': report_range},
'backgroundColor': '#7FFFD4',
'xAxis': {
'title': {
'text': 'Group:Sites'}}
}
Example 2: displays backgroundColor, not subtitle
#Create the PivotChart object
site_prod_pivotcht = PivotChart(
datasource = site_prod_ds,
series_options = [
{'options':{
'type': 'column',
'stacking': False},
'terms': [
'prod_value',
'wx_adj_value']}
],
chart_options =
{'chart':{
'title': {
'text': 'Actual versus Wx Adjusted Production Data'},
'subtitle': {
'text': report_range},
'backgroundColor': '#7FFFD4',
'xAxis': {
'title': {
'text': 'Group:Sites'}}}
}
After a bit more trial and error, I found the following works as intended.
chart_options =
{'chart':{
'backgroundColor': '#7FFFD4',
'title': {
'text': 'Actual versus Wx Adjusted Production Data'}},
'subtitle': {
'text': report_range},
'credits': {
'enabled': False},
'xAxis': {
'title': {
'text': 'Group:Sites'}}
}
I am trying to plot pie chart using Django chartit. Below is my code. I have a model racktestresult with fields PassNumber, FailNumber and Date. I am looking for a formula to plot a pie chart of only the sum of PassNumbers and sum of FailNumbers.
ds = DataPool(
series=[
{
'options': {
'source': racktestresult.objects.values('Date').annotate(
Pass=Sum('PassNumbers'), Fail=Sum('FailNumbers'))},
'terms': [
'Date', 'Pass', 'Fail'
]
}
]
)
cht3 = Chart(
datasource=ds,
series_options=[
{
'options': {
'type': 'pie', 'stacking': False,
'options3d': {'enabled': True, 'alpha': 45, 'beta': 0}
}, 'terms': {'Date': ['Fail']}
}
],
chart_options={
'title': {'text': 'Pass/Fail - Pie Chart'}
}
)
What I am trying to get is just PassNumbers and FailNumbers from racktestresult model like below. How can I achieve that?
I am creating a loop of charts and I would like to keep specified color for each category so in every chart the same category is always represented by same color, but I am completly lost. Any help, thanks
cht = Chart(
datasource = ventasdata,
series_options =
[{'options':{'type': 'line','stacking': False, 'colors': ['#00cc00', '#ff5050','#00cc00']}, # Para area cambiar a 'type': 'area'
'terms':{
'mes': [
# 'cantidad_total_mes_2015',
'cantidad_acumulado_2015'],
'mes_2014': [
# 'cantidad_total_mes_2014',
'cantidad_acumulado_2014'],
'mes_2016': [
# 'cantidad_total_mes_2016',
'cantidad_acumulado_2016']
}}],
chart_options =
# {'colors': ['#00cc00','#ff5050','#3333ff'], 'title': {
{'mes': {
'color': '#00cc00'},
'cantidad_acumulado_2014': {
'color': ['#ff5050']},
'cantidad_acumulado_2016': {
'color': ['#3333ff']},
'terms':{
# 'colors': ['#00cc00','#ff5050','#3333ff']},
'colors': [['#00cc00'],'#ff5050','#3333ff']},
'title': {
# {'title': {
'text': titulo},
'xAxis': {
'title': {'text': 'MES'}}},
x_sortf_mapf_mts = (None, monthname, False))
return cht