Dojo charting: How do you return an error if the chart is empty? - dojo

I'm pulling information from a database and putting it into a dojo chart. I'm trying to figure out how to return a 'no data message' with the way this chart is working:
var chart1 = new dojox.charting.Chart2D("traffic");
chart1.addPlot("default", {type: "Columns", gap: "15"});
chart1.addAxis("x", {minorTicks: false, font: "normal normal bold 9pt Arial",
labels: [{value: 1, text: 'Monday'},{value: 2, text: 'Tuesday'},{value: 3, text: 'Wednesday'},{value: 4, text: 'Thursday'},{value: 5, text: 'Friday'},{value: 6, text: 'Saturday'},{value: 7, text: 'Sunday'}]});
chart1.addAxis("y", {vertical: true, minorTicks: false, min: 0, font: "normal normal bold 12pt Arial"});
chart1.addSeries("Series 1", [<?php echo $trafficseries; ?>]);
chart1.setTheme(dojox.charting.themes.PlotKit.blue);
chart1.addPlot("Grid", {
type: "Grid",
hAxis: "x",
vAxis: "y",
hMajorLines: true,
hMinorLines: false,
vMajorLines: false,
vMinorLines: false
});
var anim_t = new dojox.charting.action2d.Tooltip(chart1, "default");
chart1.render();
Where would I add some sort of error handling if the data was empty?

Check, if your data has no points, and overlay a <div> over a chart with "no data" message. Otherwise hide it.

Related

Changing color of x-axis label in bar chart

I'm using react-native-charts-wrapper for creating a chart and I was wondering if there is a way to change the x-axis label style for just one bar? I have a whole week in the chart and I want to change the color of the current day. So if today is Monday I just want the M to be a different color. I don't want to change the color of the bar, just the letter under it.
These are settings for xAxis:
xAxis: {
drawAxisLine: true,
drawGridLines: false,
position: 'BOTTOM',
labelCount: 7,
valueFormatter: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
textColor: formatedColor,
axisMinimum: -1,
axisMaximum: 7,
avoidFirstLastClipping: true,
},
I checked the documentation and properties but couldn't find anything.
I think I know
core:google.charts.load('current');
ChartType: ColumnChart;
Don't use the bar
google.charts.load('current');
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: [
['Element', 'Density', { role: 'style' }],
['Copper', 8.94, '#b87333'],
['Silver', 10.49, 'silver'],
['Gold', 19.30, 'gold'],
['Platinum', 21.45, 'color: #e5e4e2' ],
],
options: {'title': 'Countries'},
containerId: 'columnchart_values'
});
wrapper.draw();
}

Remove search box with bFilter still set to True in DataTable

I need to apply custom filtering function in my datatable. For this, I need to set "bFilter": true. But I don't need search box. How can I do that?
var holiday_filter = $('#holiday_table').DataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": false,
"bInfo": false,
"order": [[0, 'desc']],
//"aLengthMenu": [5, 10, 20, 30],
'iDisplayLength': 4,
"bAutoWidth": false
});
Use dom option (default value lfrtip) without f which represents filtering input.
For example:
var holiday_filter = $('#holiday_table').DataTable({
// ... skipped ...
'dom': 'lrtip'
});

How to adjust the position of several axes in one chart?

I create a line chart using dojo. Recently, I have been applying multiple axis on the chart. But there was a problem here. It is applied to multiple axes in one place I have raised the issue of overlapping tick value. and do not change the properties of leftBottom, is there a way to adjust the shaft position? For example, x: 10, y: 20?
my code
var axisXRef = {labels : labelsample, titleOrientation : "away", stroke : {}, natural : true};
var axisYRef = {vertical : true, stroke : {}};
var chart = new Chart("chartNode");
chart.addPlot("lines", { type: Lines, tension: 3 ,min:0});
chart.addPlot("stacklines", { type: StackedLines, tension: 3 ,hAxis:"x",vAxis:"y1"});
chart.addPlot("areas", { type: Areas, tension: 3,hAxis:"x",vAxis:"y2" });
chart.custom.axisX = lang.clone(axisXRef);
chart.custom.axisY = lang.clone(axisYRef);
chart.addAxis("x", chart.custom.axisX);
chart.addAxis("y", chart.custom.axisY);
chart.addAxis("y1", {
vertical: true,
min : 50,
max:70,
leftBottom:true,
majorLabels: true, majorTicks: true, majorTick: {color:"red",length:50},
minorLabels: true, minorTicks:true, minorTick:{color:"red",length:50},
microTicks: true, microTick:{color:"red",length:50},
fixUpper: "major",
fixLower:"minor"
});
chart.addAxis("y2", {
vertical: true,
min : 0,
max:49,
leftBottom:true,
majorLabels: true, majorTicks: true, majorTick: {color:"blue",length:25},
minorLabels: true, minorTicks:true, minorTick:{color:"blue",length:25},
microTicks: true, microTick:{color:"blue",length:25},
fixUpper: "major",
fixLower:"minor"
});
Unfortunately Dojo charting only supports two axis per direction both axis being on different side of the chart. In other words you can't have two axis both on the left side of the chart. You have to have one right side using leftBottom: false property.

Dojo charting: Can i change the color of the line based on the value?

I have a working chart with Dojo 1.8.
chart1 = new dojox.charting.Chart2D("chart1");
chart1.addPlot("default", {type: "Lines", ...
chart1.addSeries("Series A", [{ x: 1, y: 2.3, tooltip: "Value 1"}, ...
My data from the series gets displayed correctly as line and the whole line (series) gets the color 'Green'.
I know how to change the color for the whole series, but would it be possible that the line changes its color based on the data values? Lets assume the x-axis is a time axis and I need the line (series) to be green for until today, and then red for the future values.
Would this be possible and how ?
(I am using markers for the values. If these could change based on the value it would be enough)
I found something something like this in the documentation:
chart.addSeries("Series A", [
{y: 4, color: "red"},
{y: 2, color: "green"},
{y: 1, color: "blue"},
{y: 1, text: "Other", **color: "white", fontColor: "red"**}
]);
But it only works for PIE-charts and not for LINES-charts.
Thank you in advance.
You could try this http://jsfiddle.net/jUS54/
Use styleFunc in the addPlot method for change the markers colors:
var chart1 = new Chart("simplechart");
chart1.addPlot("default", {type: Lines, markers:true, styleFunc: function(item {
if(item <= 2){
return { fill : "red" };
}else if(item > 3){
return { fill: "green" };
}
return {};
}});
You can change the color by adding 'fill' to your chart data. Basically, loop through your input data deciding what to set your fill too while constructing the JSON for chartData.
var chartData = [{y: 10000,fill: "red"},{y:9200,fill: "yellow"},{y:11811,fill: "green"},{y:12000,fill: "blue"},{y:7662,fill: "blue"},{y:13887,fill: "black"},{y:14200,fill: "gray"},{y:12222,fill: "purple"},{y:12000,fill: "green"},{y:10009,fill: "purple"},{y:11288,fill: "green"},{y:12099,fill: "blue"}];
http://jsfiddle.net/goinoff/QnNk2/1/

Dojo Datagrid throws "Cell is undefined"

cell = document.createElement("td");
cell.setAttribute("colspan", "1");
cell.setAttribute("valign", "top");
var grid = new dojox.grid.DataGrid({
id: "gridID",
store: new dojo.data.ItemFileWriteStore({data: {items: []}}),
elasticView: "2",
selectionMode: "single",
autoWidth: "true",
rowCount: "4",
layout: [{field: "name", editable: "false", width:"160px", name:"fieldname"}],
query: "{itemID:'*'}"
}).placeAt(cell);
grid.startup();
row.appendChild(cell);
After it starts up it throws the error "cell is undefined" (943 out of range 516)
Always double check the idiot mistakes. "Layout" should be "structure". There should be a better message popping up than cell is undefined.