Using line chart js.
Need to make checkbox which show/hide datasets
I made something like this:
lineChartData = {
labels : ["01.01.2015","012.01.2015","03.01.2015","04.01.2015","05.01.2015","06.01.2015","07.01.2015"],
datasets : dataSets
};
where dataSets is array of dataset objects, and when checkbox changed i do the next:
if($(this).prop('checked')){
myNewChart.datasets[datasetId] = dataSets[datasetId];
}
else{
myNewChart.datasets[datasetId]= {};
}
myNewChart.update();
myNewChart.datasets[datasetId]= {}; Works and delete line on graph, but adding dataset back not showing the line, however it added in myNewChart.datasets array.
Just destroy and redraw the chart. While Chart.js does support adding and removing line points - it is by label (and not by dataset - which is what you want)
Your problem was that you were emptying out the actual dataset objects - if you link it to a copy of the dataset everything works.
Here is your updated change handler
$('input:checkbox').change(function () {
var chartId = $(this).attr('data-chart-id');
var datasetId = $(this).attr('data-data-set');
dataSets[datasetId].hide = !$(this).prop('checked')
lineChartData.datasets = []
dataSets.forEach(function (dataset) {
// create a copy of the dataset to modify (if required) and put into the chart dataset array
var copy = jQuery.extend(true, {}, dataset)
if (dataset.hide)
copy.data = []
lineChartData.datasets.push(copy)
})
// create the graph from scratch
myNewChart.destroy()
myNewChart = new Chart(ctx).Line(lineChartData, chartOpt);
});
Fiddle - http://jsfiddle.net/6qdm7nwu/
Related
I'm displaying my results on an interactive grid. I'd like to be able to select multiple rows and click an edit button that will open up an “edit” form. I am having a number of problems:
Retrieve the car IDs of the rows selected. (I am having trouble accessing column values, I can access item values)
Pass a collection or array of ids to the edit form.
Save the collection.
Added more code in answer box by accident...……..
I made some progress but I am a little stuck. I followed the oracle blog and it was vey helpful. So on the attribute of the region I added the following code:
function (config) {
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3");
toolbarGroup.controls.push(
{
type: "BUTTON",
action: "updateCar",
label: "Edit Selected Cars",
hot: true,
});
config.toolbarData = toolbarData;
config.initActions = function (actions)
{
// Defining the action for activate button
actions.add(
{
name: "updateCar",
label: "Edit Selected Cars",
action: updateCar
});
}
function updateCar(event, focusElement)
{
var i, records, model, record,
view = apex.region("ig_car").widget().interactiveGrid("getCurrentView");
var vid = "";
model = view.model;
records = view.getSelectedRecords();
if (records.length > 0)
{
for (i = 0; i < records.length; i++)
{
record = records[i];
//alert("Under Development " + record[1]);
vid = vid + record[1] + "||";
apex.item("P18_CAR").setValue(vid);// This is not needed just to test
//the output
// call next page
// pass array as sql source or directly on page
}
}
}
return config;
}
This works. A button is displayed and when selected it gets the values from the interactive grid. The part I am stuck is how to call the next page and pass the multiple values (2 columns) to the page to be displayed and in a query to do an update.
Thank you if you can help me accomplish this!
Not able to get straight and curved lines in the same graph,made both the datasets bezierCurve:false and ,bezierCurve :true for them but not getting it, here is the file:http://fiddle.jshell.net/2omjx9dn/44/
need these two graph lines of the two different graphs in a single graph:
http://fiddle.jshell.net/2omjx9dn/42/
any help would be great !!!!
bezierCurve is a chart level (not a dataset level) option. So you need to override the chart to do this. The easiest way would be to plug in to the hasValue function (it gets called right before the dataset line is drawn)
Chart.types.Line.extend({
name: "LineAlt",
initialize: function (data) {
Chart.types.Line.prototype.initialize.apply(this, arguments);
var options = this.options;
this.datasets.forEach(function (dataset, index) {
var originalHasValue = dataset.points[0].hasValue;
dataset.points[0].hasValue = function () {
// change option by dataset index here
options.bezierCurve = (index === 0) ? true : false;
return originalHasValue.apply(this, arguments)
}
})
}
});
and then
...
var myLineChart = new Chart(ctx).LineAlt(data);
i had already done adding a click handler to each Segment of my doughnut chart with adding the following Code :
$("#myChart").click(
function(evt){
var activePoints = myNewChart.getSegmentsAtEvent(evt);
var chartelementid = activePoints[0].label;
alert(chartelementid);
//$('.details div').css("display", "none");
//$('#' + chartelementid).show();
}
);
This works fine, when finished it should display an additional Div with Details for this segment.
Unfortunality my labels are more then just Single Words, so i'm struggeling to create div ID's with the same name...
My Idea is to add to every Segment an additional Data like value,label, etc. so it could be an ID. but if i just add the ID information to the Segment it will not exist as variable.
Add DataType:
var dataImprove = [
{
value: 30,
color:"#001155",
highlight: "#1c2f7c",
label: "KnowHow Erhalt / Transfer & Aufbau",
id:"test"
}
]
where can i add in chart.js an additional dataType like shown above my ID to be accessible in the DOM?
kind regards Marco
As an alternative pass a JSON string as your label, then intercept to render. For example:
var canvas = document.getElementById(id);
var d = canvas.getContext("2d");
var chart = new Chart(d).Pie(json, {
segmentStrokeWidth: 1,
tooltipTemplate: "<%=label%>", //default the label
customTooltips: function (tooltip) {
// Hide if no tooltip
if (!tooltip) {
return;
}
var tooltipObj = JSON.parse(tooltip.text);
// etc
already found : between line 999 and 1023 in chart.js before drawing - i've added the line
id: ChartElements[0].id,
so the Data with the name ID is in the DOM avaiable.
I'm trying to do a chart using google api, but i have a problem on the bottom of the chart, because i want to show all bars with they respective numbers, there is my code.
I need to describe all the bars with they respective "legends".
var data = new google.visualization.DataTable();
data.addColumn("number", "x");
data.addColumn("number", "y");
for (var i = 0; i < response.x.length; i++) {
data.addRows([[response.x[i], response.y[i]]]);
}
var options = {
colors: ["#30c0cd", "#ee5f3e"],
title: "title"
};
var chart = new google.visualization.ColumnChart($("#dholder")[0]);
chart.draw(data, options);
If your x and y axis are continuous (and not discrete) the google chart api will try to find the best values and will not show every label. Try:
data.addColumn("string", "x");
how I can delete a row from a javascript function from a button
for example
If you're using a DataView, use the following:
DataView.deleteItem(RowID);//RowID is the actual ID of the row and not the row number
Grid.invalidate();
Grid.render();
If you only know the row number, you can get theRowID using:
var item = DataView.getItem(RowNum);//RowNum is the number of the row
var RowID = item.id
Suppose you are using jQuery
var grid;
$(function () {
// init options, load data
...
var columns = [];
columns[0] = {
id: 'id',
name: '#',
field: 'id', // suppose you have an id column in your data model
formatter: function (r, c, id, def, datactx) {
return 'X'; }
}
// init other columns
...
grid = new Slick.Grid($('#gridDiv'), data, columns, options);
}
function RemoveClick(databaseId, gridRow) {
// remove from serverside using databaseId
...
// if removed from serverside, remove from grid using
grid.removeRow(gridRow);
}
This is how i do it (not using any data provider though):
//assume that "grid" is your SlickGrid object and "row" is the row to be removed
var data = grid.getData();
data.splice(row, 1);
grid.setData(data);
grid.render();
I use this in a live project and it runs well. Of course, if you want to remove multiple rows then a few tweaks should be made, or if you use a data provider then you'd maybe want to remove the row only from the data provider and then have SlickGrid just refresh the rows.
Hope it helps :)
function deleteRows() {
var selectedIndexes = grid.getSelectedRows().sort().reverse();
var result = confirm("Are you sure you want to delete " + grid.getSelectedRows().length + " row(s)?");
if (result) {
$.each(selectedIndexes, function (index, value) {
var item = dataView.getItem(value); //RowNum is the number of the row
if (item)
dataView.deleteItem(item.id); //RowID is the actual ID of the row and not the row number
});
grid.invalidate();
grid.render();
}
}
var rowsToDelete = grid.getSelectedRows().sort().reverse();
for (var i = 0; i < rowsToDelete.length; i++) {
data.splice(rowsToDelete[i], 1);
}
grid.invalidate();
grid.setSelectedRows([]);
yes of course, I use it this way
var selrow = grid.getSelectedRows ();
data.splice(selrow, 1);
grid.invalidateAllRows();
grid.render ();
Greetings
hi
i'm used this script for delete row of SlickGrid
function deletefila(numrow)
{
alert("delete row"+numrow);
data.splice(numrow,1);
grid.removeAllRows();
grid.render();
//grid.removeRow(5);
//grid.updateRowCount();
//and then invalidate and re-render the grid by calling grid.removeAllRows() followed by grid.render().
}