I'm using the Google Visualizations gauge on a page, but it's important that the value its displaying is not shown as a label right below the needle.
I've found two ways of doing this. Once you navigate through the DOM to the gauge widget, and navigating into the SVG pieces, you can either set the textContent element to be an empty string, or you can delete that whole text label entity, entirely.
function removeLabel(widget) {
var gauge_label_parent = widget.getElementsByTagName("g")[1];
var gauge_label = gauge_label_parent.getElementsByTagName("text")[0];
gauge_label.textContent = "";
// Another way of getting rid of the text: remove the element
// gauge_label_parent.removeChild(gauge_label);
}
The problem is: both of those techniques work only on the first time. If I re-draw the gauge with updated values, then the label re-appears, and trying to remove the label element or set textContent="" does nothing.
So, instead of just being able to update the value with:
data.setValue(0, 1, newValue);
chart.draw(data, options);
I have discovered that I have to change the options a little bit, like:
data.setValue(0, 1, newValue);
options.minorTicks = 3; // Change the options somehow
chart.draw(data, options); // Tell gauge to draw that
options.minorTicks = 2; // Change the options back to what they were
chart.draw(data, options); // Draw again
Here's a fiddle to see how it works or doesn't. Set the fixLabel to true or false depending upon whether you want the label problem to be present or not. Keep in mind that the label will (properly) be missing the first time. It re-appears when you update its value.
http://jsfiddle.net/jemenake/72dMt/2/
So, a few questions:
Any idea why it's doing this?
Is there a way to remove the label without having to go through this option-changing business?
Bonus question: Am I unclear about how minorTicks is supposed to work, or is it broken? The docs say that it's supposed to be the number of minor ticks between majors, but setting it to 2 gives me only 1 minor tick, 3 gives me 2, etc. And, if I set it to 0 or 1, I get "Problem parsing d=''" in the console.
Adding to Madthews answer:
To those of you who are trying to remove the label from the Google Gague Chart.
If you add the following code into your page (i have placed it in the header to keep things tidy) then you can set the font size of the Label to whatever you want.
<style>
* {text-rendering: optimizeLegibility; font-size:100%;}
svg g g {font-size:0px;}
</style>
I have been toying around with this for a while now and the top line of the css above is essential otherwise it will not work!
Ok I'll try to answer:
1) Label options are not managed by current API release
https://google-developers.appspot.com/chart/interactive/docs/gallery/gauge
Workaround: try with this CSS
svg g g {
font-size:0px;
}
http://jsfiddle.net/Madthew/72dMt/17/
Above fiddle explains you the meaning of the minorThicks. It's correct that if you set 2 you get 3 "spaces". Minor thicks represent the number of "BLANK" spaces between two major thicks. In the example you will se the perfect matching between your arrow and the thin line representing the minor thick.
Instead of messing with styles, you could just insert the value with a blank formatted field.
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Unitless Indicator', {v:counter, f:''} ]
]);
This also works with addRows.
jsfiddle here: https://jsfiddle.net/08x2m4vo/2/
Use this. This is also labelled by Google.
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['', {v: <Your_own_value_of_the_gauge_meter>, f: ''}],
]);
In place of "<Your_own_value_of_the_gauge_meter>" use your value variable. That's it.
What about this?
['Label', 'Value'],
['', 80]
Related
I need to print a multiline paragraph with the first line indented using jsPDF.
I splitted my text with .splitTextToSize function using option textIndent.
Then used .text to render the result. See code below :
doc = mbjsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4'
});
var text = "To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune";
var textTab = doc.splitTextToSize(text, 100, {textIndent: 30});
doc.text(10, 20, textTab);
doc.save('test.pdf');
Actual result:
To be, or not to be, that is
the question: Whether 'tis nobler in the
mind to suffer The slings and arrows of
outrageous fortune
Expected result: (I want the first line shifted by 30mm)
To be, or not to be, that is
the question: Whether 'tis nobler in the
mind to suffer The slings and arrows of
outrageous fortune
Not sure about option textIndent, but if you have only one paragraph, you may simply add a tab to the beginning of that paragraph.
var textTab = doc.splitTextToSize(' ' + text, 100);
I mainly use jsPDF to convert HTML to PDF. If you just want to convert plain text, maybe you can consider pdfmake as well. It has an auto page break and is easy to add the margin, etc.
<script src="http://pdfmake.org/build/pdfmake.min.js"></script>
<script src="http://pdfmake.org/build/vfs_fonts.js"></script>
<script>
function print() {
// open the PDF in a new window
pdfMake.createPdf(dd).open();
}
var dd = {
content: [{
leadingIndent: 30,
lineHeight: 1.5, // optional
text: "To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune"
}]
}
</script>
textIndent is used for the space between lines, it's really confusing!
You could make the first line a seperate text component. Than you can change the x parameter of the Text class.
i want to add the value for each label on pie chart legend and not just the label itself. on chart.js there was an option to add legend template but it seems to not working on newchart.js
I just had the same problem and played with some time with overriding the "legendTemplate" option. I seems that the default legendTemplate uses the invalid variable "datasets" which should be now "segments".
So the solution could look like the following:
copy default value for legendTemplate
replace all "datasets" with "segments"
add "<%=segments[i].value%>" to the end
Example:
myNewChart = new Chart(chartContext).Pie(data, {
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].strokeColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%> <%=segments[i].value%><%}%></li><%}%></ul>"
});
Sadly, I couldn't fix the css for the legend so the color coding etc. won't display.
Changing my Line Chart's x-axis labels from one bit of text to another bit of text isn't working; what am I doing wrong, please?
I have a Line Chart whose discrete x-axis is labeled with text representations of the date.
(I'm using corechart; I've created a dataTable, created a dataView based off of that, and have created the chart as a ChartWrapper).
I'm filtering the dataView based on the textual date, so my initial x-axis domain values are in the format 2013-09-01... and that works. But now I need to change the x-axis labels to the format 9/2013. The examples I've found on this seem clear, but the chart isn't drawn but is replaced by an error: "c is null". Googling that, the problem sounds like my domain column is the wrong data type, but I don't see how that's possible.
Can you please point out my error? Below, I've gotten the list of columns that I need displayed; that would be a list like [0,3,5] where 0 is the domain column. I remove it first so I can set the new, formatted column:
// Format the x-axis as n/Y
// remove unformatted column 0;
view_col_list.splice(0, 1);
data_displayed.setColumns([
{
role: 'domain',
calc: function(dataTable, row) {
var my_date = new Date(dataTable.getValue(row, 0));
console.info('the date I want to format: %o',my_date);
// this does in fact produce "9/2013"
console.info('the date I want to show' + my_date.getMonth() + '/' + my_date.getFullYear());
return my_date.getMonth() + '/' + my_date.getFullYear();
},
type: 'string',
sourceColumn: 0,
id: 0
},
view_col_list
]);
I would guess that your dates are probably not the problem, but there are a few things I would recommend changing with them: remove the "sourceColumn" attribute, as it isn't needed; and change the way you are constructing your new date string, as converting a string to a Date object is inconsistent across browsers. Also, the #getMonth method returns the 0-indexed month, so "2013-09-01" would get turned into "8/2013" in your code (assuming the date string conversion works). There is an easier way that doesn't involve converting to Date objects and back into strings:
var dateArray = dataTable.getValue(row, 0).split('-');
return dateArray[1] + '/' + dateArray[0];
I suspect the problem is caused by this:
view_col_list.splice(0, 1);
data_displayed.setColumns([{...}, view_col_list]);
which is equivalent to data_displayed.setColumns([{...}, [...]]); which definitely won't work. Rather than splice the first element from the view_col_list, replace it with your object:
view_col_list[0] = {...};
data_displayed.setColumns(view_col_list);
I have a list of products and I am trying to alternate the colour between each product (grey, white, grey, white, and so on). I understand how to use colour formatting based on a condition such as the following link: example followed. However I dont know how to get it to look at the previous line on the report and check whether it holds the same product name. If it does, then colour the row the same colour, else the alternate colour.
I've setup an example report in the application: Application 67666 - Colour Row by Product example. I have two products in the report so I'm trying to get 3 grey lines and then 3 white lines, if I had more products it would then go back to grey and so on.
Link:apex.oracle.com
workspace: apps2
user: user
password: DynamicAction2
Please could I be directed in the right direction, JavaScript and Dynamic Actions shout out to me as in the example link however its looking at the previous row which is getting me all stuck.
I can't think of another solution than javascript really. There is possibly using lag in the sql, but only to use it to determine where the row color should change. You could use the value of the column in a html expression of a column and put it in a class, but you still need to iterate over it with javascript anyway. So it seems less fiddly to just use javascript.
Inline CSS:
table.report-standard tr.normalRow td{
background-color: green;
}
table.report-standard tr.altRow td{
background-color: red;
}
This will override the default style, but you will need to tune this to your demands. For example, the color change on :hover of the row. I prefer steering the style through assigning classes and then define the rules in css than to directly assign css through javascript (which would place it in style tags, ugh).
Dynamic action: change row colour
After Refresh, Region, Product Report
True action: execute javascript code, fire on page load checked
$('td[headers="PRODUCT"]', this.triggeringElement).each(function(){
var lCurrRow = $(this).closest('tr'),
lPrevRow = lCurrRow.prev(),
lPrevVal = lPrevRow.find('td[headers="PRODUCT"]').text();
console.log(lPrevVal + ' - ' + $(this).text());
//if value on previous row differs from the that on the current row
//then change the class
//if the value didnt change, then use the same class as the previous row
if ( lPrevVal != $(this).text() ){
if ( lPrevRow.hasClass('normalRow') ){
lCurrRow.addClass('altRow');
} else {
lCurrRow.addClass('normalRow');
};
} else {
if ( lPrevRow.hasClass('normalRow') ){
lCurrRow.addClass('normalRow');
} else {
lCurrRow.addClass('altRow');
};
};
})
Check your solution on apex.oracle.com, I implemented it there.
Can somebody please tell me how can i show the Total Collection on MSChart
You can use chart.Annotations property to get a similar result.
For example with the following code (located after filling the chart):
var ann = new RectangleAnnotation();
ann.Text = "Total Collection" + Environment.NewLine + "250 Billion";
ann.IsMultiline = true;
ann.AxisX = this.chart1.ChartAreas[0].AxisX;
ann.AxisY = this.chart1.ChartAreas[0].AxisY;
ann.AnchorX = 9; // as you can see from the image below,
ann.AnchorY = 41; // these values are inside the range
// add the annotation to the chart annotations list
this.chart1.Annotations.Add(ann);
I got the following result:
N.B.:
there are a lot of annotations types (CalloutAnnotation, EllipseAnnotation...) and they have a lot of properties to change styles and behaviors. You can even set a property to allow annotation moving (i.e. AllowMoving=true).
Have a look to annotation properties through intellisense or MSDN.
You can set the property IsDockedInsideChartArea to true. You will also need to specify which ChartArea the legend is docked to, and set the position property to Auto.
legend.IsDockedInsideChartArea = true;
legend.DockedToChartArea = "ChartArea1";
There are more information about this and other legend properties here.