I want to add new button in list of exporting of charts,
i want to perform something like that :
http://jsfiddle.net/3GNZC/189/
but using DotNet HighCharts,
i already Tried to do that:
DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart1")
.InitChart(new Chart
{
BorderColor = System.Drawing.Color.Gray,
Height = ChartHeight
});
chart.SetExporting(new Exporting
{
Buttons = new ExportingButtons()
{
ContextButton = new ExportingButtonsContextButton()
{
MenuItems = **what can i write here!**
}
},
Enabled = true,
});
my problem here that i can not add new MenuItems to ContextButton without deleting the options that already exist like(Download PNG Image,....)
Definitely it's a bug which requires the package developer intervention. I reported it directly to wrapper developer, so we need to wait for the decision. To workaround it, you can temporary paste the code below to your <script> tag in .cshtml, which adds the button globally to Highcharts object, and bypassing .Net.
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
#using Highsoft.Web.Mvc.Charts
<script type="text/javascript">
Highcharts.getOptions().exporting.buttons.contextButton.menuItems.push({
text: 'Add Issue ',
onclick: function() {
alert('OK');
}
function formatXAxis() {
return this.value; // clean, unformatted number for year
}
function formatYAxis() {
return this.value / 1000 + 'k';
}
</script>
#(Html.Highsoft().GetHighcharts(
new Highcharts
{
Title = new Title
{
Text = "US and USSR nuclear stockpiles"
},
Subtitle = new Subtitle
{
Text = "Source: <a href='http://thebulletin.metapress.com/content/c4120650912x74k7/fulltext.pdf'>thebulletin.metapress.com</a>"
},
XAxis = new List<XAxis>
{
new XAxis
{
AllowDecimals = false,
Labels = new XAxisLabels
{
Formatter = "formatXAxis"
}
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Title = new YAxisTitle
{
Text = "Nuclear weapon states"
},
Labels = new YAxisLabels
{
Formatter = "formatYAxis"
}
}
},
Tooltip = new Tooltip
{
PointFormat = "{series.name} produced <b>{point.y:,.0f}</b><br/>warheads in {point.x}"
},
PlotOptions = new PlotOptions
{
Area = new PlotOptionsArea
{
PointStart = 1940,
Marker = new PlotOptionsAreaMarker
{
Enabled = false,
Symbol = "circle",
Radius = 2,
States = new PlotOptionsAreaMarkerStates
{
Hover = new PlotOptionsAreaMarkerStatesHover
{
Enabled = true
}
}
}
}
},
Series = new List<Series>
{
new AreaSeries
{
Name = "USA",
Data = #ViewData["usaData"] as List<AreaSeriesData>
},
new AreaSeries
{
Name = "USSR/Russia",
Data = #ViewData["russiaData"] as List<AreaSeriesData>
}
}
}
, "chart")
)
Related
Ref: 3d Force Directed Graph - Replacing Nodes with Images
How might I add the images to the following excellent code in the same manner as the Stack Overflow answer above?
https://github.com/jexp/neo4j-3d-force-graph/blob/master/particles.html
Assuming that each node may have a property of n.image=/images/imagexxx.jpg how might I apply this image from a local filesystem to its respective node ?
If the property isn't present then render the node as the normal sphere.
Here is my sample code which just renders all nodes as small_image.jpg :
const elem = document.getElementById('3d-graph');
const driver = neo4j.v1.driver("bolt://192.168.1.251", neo4j.v1.auth.basic("neo4j", "test"));
const session = driver.session();
const start = new Date()
session
.run('MATCH (n)-[r]->(m) RETURN { id: id(n), label:head(labels(n)), community:n.name, caption:n.name, size:log(n.links_from+n.links_to)} as source, { id: id(m), label:head(labels(m)), community:m.name, caption:m.name, size:log(m.links_from+m.links_to)} as target, {weight:r.weight, type:type(r), community:case when n.community < m.community then n.community else m.community end} as rel LIMIT $limit', {limit: 5000})
.then(function (result) {
const nodes = {}
const links = result.records.map(r => {
var source = r.get('source');source.id = source.id.toNumber();
nodes[source.id] = source;
var target = r.get('target');target.id = target.id.toNumber();
nodes[target.id] = target;
var rel = r.get('rel'); if (rel.weight) { rel.weight = rel.weight.toNumber(); }
return Object.assign({source:source.id,target:target.id}, rel);
});
session.close();
console.log(links.length+" links loaded in "+(new Date()-start)+" ms.")
const gData = { nodes: Object.values(nodes), links: links}
const Graph = ForceGraph3D()(elem)
.graphData(gData)
.nodeAutoColorBy('community')
.nodeVal('size')
.linkAutoColorBy('community')
.linkWidth(0)
.linkDirectionalParticles('weight')
.linkDirectionalParticleSpeed(0.001)
.nodeLabel(node => `${node.label}: ${node.caption}`)
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null)
.nodeThreeObject(node => {
var map = new THREE.TextureLoader().load( "small_image.jpg" );
map.minFilter = THREE.LinearFilter;
var material = new THREE.SpriteMaterial( { map: map } );
var sprite = new THREE.Sprite( material );
sprite.scale.set(32,32,1);
return sprite;
});
// Spread nodes a little wider
Graph.d3Force('charge').strength(-150);
})
.catch(function (error) {
console.log(error);
});
const elem = document.getElementById('3d-graph');
const driver = neo4j.v1.driver("bolt://localhost", neo4j.v1.auth.basic("neo4j", "test"));
const session = driver.session();
const start = new Date()
session
.run('MATCH (n:Entity)-[r]->(m:Entity) WHERE n.name="new york" RETURN { id: id(n), label:head(labels(n)), community:n.name, caption:n.name, image:n.image, size:log(n.links_from+n.links_to)} as source, { id: id(m), label:head(labels(m)), community:m.name, caption:m.name, image:m.image, size:log(m.links_from+m.links_to)} as target, {weight:r.weight, type:type(r), community:case when n.community < m.community then n.community else m.community end, image:case when n.image < m.image then n.image else m.image end} as rel LIMIT $limit', {limit: 5000})
.then(function (result) {
const nodes = {}
const links = result.records.map(r => {
var source = r.get('source');source.id = source.id.toNumber();
nodes[source.id] = source;
var target = r.get('target');target.id = target.id.toNumber();
nodes[target.id] = target;
var rel = r.get('rel'); if (rel.weight) { rel.weight = rel.weight.toNumber(); }
return Object.assign({source:source.id,target:target.id}, rel);
});
session.close();
console.log(links.length+" links loaded in "+(new Date()-start)+" ms.")
const gData = { nodes: Object.values(nodes), links: links}
const Graph = ForceGraph3D()(elem)
.graphData(gData)
.nodeAutoColorBy('community')
.nodeVal('size')
.linkAutoColorBy('community')
.linkWidth(0)
.linkDirectionalParticles('weight')
.linkDirectionalParticleSpeed(0.001)
.nodeLabel(node => `${node.label}: ${node.caption}`)
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null)
.nodeThreeObject(node => {
var map = new THREE.TextureLoader().load((node.image != null ? node.image : ""));
map.minFilter = THREE.LinearFilter;
var material = new THREE.SpriteMaterial( { map: map } );
var sprite = new THREE.Sprite( material );
sprite.scale.set(32,32,1);
if (node.image){
return sprite; }
else return false;
});
// Spread nodes a little wider
Graph.d3Force('charge').strength(-150);
})
.catch(function (error) {
console.log(error);
});
By one trick or another I managed to handle headers in both new windows (window.open, target=blank etc) and iframes with SlimerJS. It is also possible to change navigator data (such as navigator.appVersion) for new windows, but I'm stuck with doing this for iframes. It looks like the onInitialized method works correcrtly only for main window and new windows, but not for iframes.
Here is some parts of the code.
var headers =
{
"Accept-Language" : "test_language",
"Accept" : "test/accpet",
"Connection" : "keep-alive",
"Keep-Alive" : "333",
"Accept-Charset" : "test-utf",
"User-Agent" : "test_ua"
}
var webpage = require('webpage').create(
{
pageSettings:
{
javascriptEnabled: true,
loadImages: true,
loadPlugins: true,
}
});
_onPageCreated = function(childPage)
{
console.log('a new window is opened');
childPage.settings.userAgent = options.useragent["navigator.userAgent"];
childPage.customHeaders = headers;
childPage.viewportSize = { width:400, height: 500 };
childPage.onInitialized = _onInitialized;
childPage.onNavigationRequested = _onNavigationRequested;
childPage.onLoadStarted = _onLoadStarted;
childPage.onLoadFinished = _onLoadFinished;
childPage.onResourceRequested = _onResourceRequested;
childPage.onPageCreated = _onPageCreated;
};
_onResourceRequested = function(requestData, networkRequest)
{
for(var h in headers)
{
networkRequest.setHeader(h, headers[h], false);
}
...
}
var _onInitialized = function()
{
this.customHeaders = headers;
console.log("[webpage.onInitialized]");
this.evaluate(function(options)
{
(function()
{
window.navigator.__defineGetter__('appVersion', function ()
{
return options.useragent["navigator.appVersion"];
});
...
})();
}, options);
};
...
webpage.onInitialized = _onInitialized;
webpage.onNavigationRequested = _onNavigationRequested;
webpage.onLoadFinished = _onLoadFinished;
webpage.onResourceRequested = _onResourceRequested;
webpage.onPageCreated = _onPageCreated;
I tried to do this with PhantomJS, but it seems like it is not possible to use "this" instead of "webpage" in the following case:
var _onInitialized = function()
{
console.log("[webpage.onInitialized]");
this.evaluate(function() // <<---not working
{
});
console.log("test"); //is not being printed
};
I would like this function to work with "this" object, so that it could be defined as onInitialized for both main page and child pages.
Anyway, the main question is about the SlimerJS code, not the Phantom one.
I am using knockout.js in my django project and having problem in post method in javascript. I tried to rebind or re-initialized the list but it didn't work.
Eg: I am showing table data with 10 rows..I want on button click I get another data with 5 rows and want to reload that data on table without reloading the page.
Does any one knows the solution .. Below is my code for knockout.js, html and view.py page:
javascript:
function makeShowObjectList(model, d_url, no_num, detail_per_page, b, fruit) {
var showobjectList = ko.observableArray([]);
$.post(d_url, data, function (response_data) {
// here we have applied code to set new data in showobjectList
if (!showobjectList.is_ready)
{
//Here we are trying to relaod the list on the page but did'nt work
FViewModel.showobjectList=showobjectList;
showobjectList.is_ready = true;
showobjectList.onready();
ko.mapping.fromJSshowobjectList, {}, self); }
}
}, 'json');
}
function fruitFilterItem( n, i ) {
this.n = n;
this.i = i;
}
var FViewModel=function(c_data)
{
var self = this;
self.abc= ko.observable(null);
this.optionsText = ko.observable();
this.fruitFilter = ko.observableArray([
new fruitFilterItem( "Mango", 2 ),
new fruitFilterItem( "Banana", 1 ),
new fruitFilterItem( "Grapes", 3 )
]);
this.selectedfruit = ko.observable();
this.VegeFilter = ko.observableArray([
new fruitFilterItem( "Tomato", "Tomato" ),
new fruitFilterItem( "Patato", "Patato" ),
new fruitFilterItem( "Onion", "Onion" ),
]);
this.selectedVege = ko.observable();
self.showtList = makeShowObjectList(BucketViewModel, urls.get_fruit_info, self.fruit_page, self.num_fruit, self.bbq,
self.selectedfruit());
self.setShowType = function(d, ele) {
this.get_updates = function () {
ko.mapping.fromJS(searchList(), self);};
self.showtList = makeShowObjectList(BucketViewModel, urls.get_fruit_info, self.fruit_page, self.num_fruit, self.b, self.selectedfruit());
self.showtList();
}
self.ShowmessageList = function () {
return self.showtList;
}
}
HTML:
<script>
VarModel = new FViewModel(c_data);
$(function() {
function get_updates () {
$.getJSON('/new-lines.json', function(c_data) {
var VarModel = ko.mapping.fromJS(choices_data);
ko.applyBindings(VarModel );
});
}
ko.applyBindings(VarModel);
</script>
<body>
<select id="fruit" name="fruit" style="width:200px;" data-bind = "
value: selectedfruit,
options: fruitFilter,
optionsText: 'n',
optionsValue: 'i',
optionsCaption: 'Select a fruit'
">
</select>
<select style="width:180px;" data-bind = "
value: selectedVege,
options: VegeFilter,
optionsText: 'n',
optionsValue: 'i',
optionsCaption: 'Select a Vege'
">
//here we are showing our columns
</body>
Views.py:
def urls.get_fruit_info(request):
//we are calculating the page_object here
response_object = {
'page': page_object,
'no_not': FruitRecipient.objects.filter(user=request.member, add_at=None).count()
}
return HttpResponse(simplejson.dumps(response_object, indent=3))
I would be thankful if any one could help me out in sorting my issue.
Thanks in advance.
Use ko.mapping its a plugin that you can download, it only updates the observables that have changed between two states, thus only the members that have changed will be re re-rendered in the view
i'm trying to create a chart using dojo. I choose a StackedColumns chart. I want to make it interactive. When a user clicks on a graph columns, an hyperlink should be invoked. But to create hyperlink'url, I need the series name. Is there any way to get Series Name when user clicks on a column? I've been searching for days but i didn't found any solution. Here is my code:
<div id="chartNode" style="width: 1024px; height: 768px;"></div>
<div id="legend"></div>
<script type="text/javascript">
require(['dojox/charting/Chart',
'dojox/charting/themes/PrimaryColors',
'dojox/charting/plot2d/StackedColumns',
'dojox/charting/plot2d/Grid',
'dojox/charting/widget/Legend',
'dojox/charting/action2d/Tooltip',
'dojox/charting/action2d/Magnify',
'dojox/charting/action2d/Highlight',
'dojo/store/Observable',
'dojo/store/Memory',
'dojox/charting/StoreSeries',
'dojox/charting/axis2d/Default',
'dojo/domReady!'], function(Chart, theme, StackedColumns,Grid,Legend,Tooltip,Magnify,Highlight,Observable,Memory,StoreSeries){
var myData = [{id:1,value:1,site:'1'},
{id:2,value:2,site:'1'},
{id:3,value:6,site:'1'},
{id:4,value:4,site:'1'},
{id:5,value:5,site:'1'},
{id:6,value:1,site:'2'},
{id:7,value:3,site:'2'},
{id:8,value:1,site:'2'},
{id:9,value:2,site:'2'},
{id:10,value:7,site:'2'}];
var myStore = new Observable(new Memory({
data: { identifier: 'id',
items: myData
}
}));
var serie_1 = new StoreSeries(myStore, { query: { site: 1 } }, 'value');
var serie_2 = new StoreSeries(myStore, { query: { site: 2 } }, 'value');
var myChart = new Chart('chartNode');
myChart.setTheme(theme);
myChart.addAxis('x', { fixLower: 'minor',
fixUpper: 'minor',
natural: true,
rotation: 90
});
myChart.addAxis('y', {vertical: true,fixLower: 'major',fixUpper: 'major',minorTicks: true,includeZero: true});
myChart.addPlot('myPlot', { type: 'StackedColumns', gap: 5, minBarSize: 8});
myChart.addSeries('Serie 1',serie_1,{ stroke: { color: 'red' }, fill: 'lightpink' });
myChart.addSeries('Serie 2',serie_2,{ stroke: { color: 'blue' }, fill: 'lightblue' });
var highlight = new Highlight(myChart, 'myPlot');
myChart.render();
var legend = new Legend({ chart: myChart }, 'legend');
myChart.connectToPlot('myPlot',function(evt) {
// React to click event
if(type == 'onclick') {
var msg = 'x:'+evt.x+';y:'+evt.y+';index: '+evt.index+';value: '+evt.run.data[evt.index];
alert(msg);
//How to get series informations when onclick event fires???
}
var tip = new Tooltip(myChart,'myPlot',{text:function(evt){return evt.run.data[evt.index];}});
});
});
</script>
I tried this in a stacked bar and works well:
chart.connectToPlot("default", function(evt) {var type = evt.type; if(type=="onclick") console.log(evt.run.name);})
evt.run.name provides the series name based on the column you clicked
Great! Thank you Noelia!
I have used it for a pie chart. You can get the index number of the slice with the parameter evt.index.
I am looking for a drop down list which can present the user with a series of images to choose from. Each image will be about 50x50 pixels and a small text description will be under the image. A jQuery and compatable ASP.NET solution would be preferred.
I wrote a super basic jQuery plug in to accomplish this. What will happen is a a fake drop down list will be created from an existing select tag. The original select will be hidden, and the fake menu will be shown. As the new menu is being created, it will callback to get the HTML to show for each option. In this function you can pass back an image.
(function($) {
$.fn.templatedSelect = function(options) {
var defaults = {
selectHandleImage : "selectHandle.gif",
width : "65px",
getOption : function(value, text) {
return text;
}
};
var opts = $.extend(defaults, options);
var $originalSelect = this;
var $container = $(document.createElement('div'))
.css("clear", "both")
.css("width", opts.width)
.hover(
function () {
$selectBox.css("border-color", "#000000");
},
function () {
if (!$menuItems.is(":visible"))
$selectBox.css("border-color", "#C0C0C0");
})
.attr('id', "imageSelect_container_" + this.attr('id'));
var $selectBox = $(document.createElement('div'))
.css("border", "solid 1px #C0C0C0")
.css("overflow", "hidden")
.css("width", "100%")
var $selectedItem = $(document.createElement('div'))
.css("padding", "4px");
var $selectHandle = $(document.createElement('div'))
.css("float", "right")
.css("background-color", "#F0F0F0")
.css("padding", "4px")
.css("cursor", "hand")
.click(function(e) {
ToggleMenuItems();
})
.html(
$(document.createElement('img')).attr("src", opts.selectHandleImage)
);
var $menuItems = $(document.createElement('div'))
.css("position", "absolute")
.css("margin-top", "-1px")
.css("border", "solid 1px #000000")
.css("background-color", "#FFFFFF")
.hide();
$originalSelect.children("option").each(function(i, selected) {
var $menuItem = $(document.createElement('div'))
.css("padding", "4px")
.html(opts.getOption($(this).val(), $(this).text()))
.val($(this).val())
.click(function(e) {
ToggleMenuItems();
$originalSelect.val($(this).val());
$selectedItem.html($(this).html());
})
.hover(
function () {
$(this).css("background-color", "#81BEF7");
},
function () {
$(this).css("background-color", "#FFFFFF");
})
.appendTo($menuItems);
});
//preset the selectedItem
$selectedItem.html(
$menuItems.children("div:eq("+$originalSelect[0].selectedIndex+")").html()
);
//put everything together
$selectBox.appendTo($container);
$selectHandle.appendTo($selectBox);
$selectedItem.appendTo($selectBox);
$menuItems.appendTo($container);
//hide the original select and put ours in
$originalSelect.hide();
$container.insertBefore($originalSelect);
$selectHandle.height($selectBox.height());
$menuItems.width($selectBox.width());
function ToggleMenuItems() {
if ($menuItems.is(":visible")) {
$menuItems.hide();
$selectBox.css("border", "solid 1px #C0C0C0");
} else {
$menuItems.show();
$selectBox.css("border", "solid 1px #000000");
}
}
}})(jQuery);
To use, call templatedSelect on your existing select. Also pass in a function to resolve the template for each item
$().ready(function() {
$('#selectId').templatedSelect({
getOption : function(v, t) {
return "<img src='" + v + "'/><br/>" + t;
}
});