I'have the following code which has a problem.
//reset the yAxis with new value
$$("chartStock1").yAxis_setter({ start:lowestValue, step:stepValue, end:highestValue, template:function(value){ return value } });
//clear data
$$("chartStock1").clearAll()
//reload data
$$("chartStock1").parse(jiugangArray);
I'd like to reset the yAxis of the line chart and the values seems OK. Then I reload the data by the 'parse' function and the data in the array is also OK.
The line chart was drawn due to the older yAxis, but not due to the brand-new yAxis value. This is quite confusing.
It is more correct to use define() method instead of setter:
$("chartStock1").define("yAxis",{
start:lowestValue,
step:stepValue,
end:highestValue,
template:function(value){ return value }
});
Related
I have a pie chart created dynamically, that uses function createPieChart() described below. When a slice is clicked, I want to call a function to print out the label and value of that slice.
I am facing 2 problems:
Although I connect "clicked" or "pressed" or "released" signals, the slot is not reached. I am using qtcharts 2.0 (I cannot update right now).
I am able to connect "hovered" signal, but without passing any parameter, so I don't know what slice I am into.
These are the other functions:
function createPieChart(data){
pieserieschart.clear();
slices.splice(0, slices.length) //clear slices array
for (var prop in data) {
slices.unshift(pieserieschart.append(prop, data[prop]));
//I get "Cannot read property 'label' of undefined using this method
slices[0].hovered.connect(function(){mouseHoverSlice(slices[0].label));
//WORKS, but I want to pass the label of that slice (and the value if possible)
slices[0].hovered.connect(mouseHoverSlice);
//it is not working at all
slices[i].clicked.connect(sliceClicked);
}
function sliceClicked(){
console.log("Slice Clicked"); //I cannot see this printed
}
function mouseHoverSlice(info){
console.log("Slice hover: " + info);
}
Any idea of how to do it? Thanks!
After upgrade to QtCharts 2.2 I was able to solve it like this:
For pie & line & scatter plots, I used onClicked, which returns the slice/point. So you don't need to connect any signal when creating the slices or points dynamically.
For bar charts, I was able to connect the barset created
var barvalues = barserieschart.append("label",values)
barvalues.clicked.connect(barClicked)
...
ChartView {
PieSeries {id: pieserieschart; onClicked: sliceClicked(slice) }
BarSeries {id: barserieschart }
ScatterSeries{id: scatterserieschart; onClicked: scatterclicked(point)}
}
Another developer created our original map but I'm tasked with making some changes. One of these is making sure the activated marker is brought to the front when clicked on (where it is partially overlapped by other markers).
The developers have used mapbox 2.2.2.
I have looked at leafletjs's docs, have followed some instructions on other posted solutions (e.g. solution one and solution two). Neither of these makes any difference.
Examining the marker in Chrome's console I can see the value of options.zIndexOffset is being set (10000 in my test case). I've even set _zIndex to an artificially high value and can see that reflected in the marker's data structure. But visually nothing is changing.
This is how the map is set up initially. All features are from a single geojson feed:
L.mapbox.accessToken = '<access token here>';
var map = L.mapbox.map('map', 'map.id', {
}).setView([37.8, -96], 3);
var jsonFeed, jsonFeedURL;
var featureLayer = L.mapbox.featureLayer()
.addTo(map)
.setFilter(function (f) {
return false;
});
$.getJSON(jsonFeedURL, function (json) {
jsonFeed = json;
jsonFeedOld = json;
// Load all the map features from our json file
featureLayer.setGeoJSON(jsonFeed);
}).done(function(e) {
// Once the json feed has loaded via AJAX, check to see if
// we should show a default view
mapControl.activateInitialItem();
});
Below is a snippet of how I had tried setting values to change the z-index. When a visual marker on the featureLayer is clicked, 'activateMarker' is called:
featureLayer.on('click', function (e) {
mapControl.activateMarker(e);
});
The GEOjson feed has urls for the icons to show, and the active marker icon is switched to an alternative version (which is also larger). When the active feature is a single Point I've tried to set values for the marker (lines commented out, some of the various things I've tried!)
activateMarker: function (e) {
var marker = e.layer;
var feature = e.layer.feature;
this.resetMarkers();
if (feature.properties.hasOwnProperty('icon')) {
feature.properties.icon['oldIcon'] = feature.properties.icon['iconUrl'];
feature.properties.icon['iconUrl'] = feature.properties.icon['iconActive'];
feature.properties.icon['oldIconSize'] = feature.properties.icon['iconSize'];
feature.properties.icon['iconSize'] = feature.properties.icon['iconSizeActive'];
}
if (feature.geometry.type == 'Point') {
marker.setZIndexOffset(10001);
marker.addTo(featureLayer);
}
//featureLayer.setGeoJSON(jsonFeed);
}
Any advice would be greatly appreciated! I'm at the point where I don't know what else to try (and that's saying something).
What probably happens is that you just flush your markers with the last call to .setGeoJSON():
If the layer already has features, they are replaced with the new features.
You correctly adjust the GeoJSON data related to your icon, so that when re-created, your featureLayer can use the new values to show a new icon (depending on how you configured featureLayer).
But anything you changed directly on the marker is lost, as the marker is removed and replaced by a new one, re-built from the GeoJSON data.
The "cleanest" way would probably be to avoid re-creating all features at every click.
Another way could be to also change something else in your GeoJSON data that tells featureLayer to build your new marker (through the pointToLayer option) with a different zIndexOffset option.
I'm trying to write a method in GWT to override the series.show function for all Highcharts series, on show I want to essentially copy the series, remove the series from the chart, and readd it so that showing the series will redraw the line (instead of the default behavior where the line appears and the chart redraws). I have this modeled in a Jsfiddle: http://jsfiddle.net/ax3o8uf3/16/
I used Moxie's highcharts wrapper for GWT and used the setSeriesPlotOptions() method to set the series show event handler and call this native method from inside the onShow().
public static native void showSeries(JavaScriptObject series, JavaScriptObject chart) /*-{
var options = series.options;
options.color = series.color;
options.index = series.index;
options.marker.symbol = series.symbol;
series.remove();
options.visible = true;
chart.addSeries(options);
}-*/;
and everything worked fine. Then we updated the project's highcharts and highstock.js files and it broke everything. Now hiding and showing a series in the legend will cause it to redraw fine for the first series you do it for, but as soon as you try and show another series it breaks and goes back to the default functionality for all series. Any ideas on what I'm doing wrong or what might be causing it to not work after showing a second series on the graph?
I'm not sure why but for some reason using the seriesShowEventHandler() caused it to break after trying to show more than one series, the solution I came up with was something like this:
setSeriesPlotOptions(new SeriesPlotOptions().setSeriesLegendItemClickEventHandler(new SeriesLegendItemClickEventHandler() {
#Override
public boolean onClick(SeriesLegendItemClickEvent seriesLegendItemClickEvent) {
Series series = getSeries(seriesLegendItemClickEvent.getSeriesId());
if(seriesLegendItemClickEvent.isVisible()) {
series.hide();
} else if((series.getOptions().get("type").toString()).equals("\"line\"")){
removeAndReAddSeries(getNativeChart(), series.getNativeSeries());
} else {
series.show();
}
return false;
}
}));
I am trying to add series to my chart application using gwt-highchart (using the latest gwt-highchart 1.6.0 and Highstock 2.3.4 versions). Everything seems fine until the third series. When I try to add the third one I got this error:
com.google.gwt.core.client.JavaScriptException: (String)
#org.moxieapps.gwt.highcharts.client.BaseChart::nativeAddSeries(Lcom/google/gwt/core
/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;ZZ)([JavaScript
object(4953), JavaScript object(5135), bool: true, bool: true]): Highcharts error #18:
www.highcharts.com/errors/18
And here is my code (runs within a loop):
// Create a new serie with a new yAxis
Series newSeries = chart.createSeries().setYAxis(index).setPlotOptions(new LinePlotOptions().setColor(tag.getColor()));
// Set new yAxis options
chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60).setStartOnTick(false)
.setEndOnTick(false).setGridLineWidth(0).setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING)
.setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor())));
// Add the serie to the chart
chart.addSeries(newSeries.setName("Test " + index));
First two series are OK as I said before but third one throws the above exception (when I debug the application, I can see the newly created yAxis references).
Here is the line which throws the exception:
chart.addSeries(newSeries.setName("Test " + index));
Thanks
I've figured it out finally!
GWT-HighCharts seems to be the problem. It does not add the new YAxis to the Chart at all. So you must add YAxis via native calls like this;
private static native void nativeAddAxis(JavaScriptObject chart, JavaScriptObject axisOptions, boolean isX, boolean redraw, boolean animationFlag) /*-{
chart.addAxis(axisOptions, isX, redraw, animationFlag);
}-*/;
Just call this native method before adding the new series.
// Create new series
Series newSeries = chart.createSeries().setYAxis(index);
newSeries.setPlotOptions(new LinePlotOptions().setColor(tag.getColor()));
newSeries.setName(index + 1 + ") ");
// Create a new YAxis
YAxis yAxis = chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60)
.setStartOnTick(false).setEndOnTick(false).setGridLineWidth(0).setPlotLines().setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING)
.setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor())));
// IMPORTANT!: New YAxis must be added to the chart via native calls since gwt-highcharts wrapper doesn't do that properly!
nativeAddAxis(chart.getNativeChart(), yAxis.getOptions().getJavaScriptObject(), false, false, false);
// Physical attach
chart.addSeries(newSeries);
Here is the cause of this type of errors:
If you are using GWT-HighCharts wrapper, you must make the configuration before adding chart to DOM! It seems that after adding it to the DOM, any configuration changes does not seem to work at all!
Happy coding!
please check the index value.
if index is more than the axis count this error may occur
highcharts error #18 indicates that the axis trying to access does not exist.
here is the link http://www.highcharts.com/errors/18
Hope that will help you
I have two line series and how do I make points on both series selected at the same time? Basically, my chart has 2 y values sharing the same x value and I'm representing them as two series. I want to display both points as selected for a given X Value.
Hi there,Thanks for the reply. I'm doing that in
- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
SChartDataPoint* point1Series1 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:0];
point1Series1.selected = YES;
SChartDataPoint* point1Series2 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:1];
point1Series2.selected = YES;
When I print the selected state of both points after this line of code, they return 1(selected) but they don't seem to appear as selected on the chart only the one I selected on the chart on device seem to appear as selected though I'm calling redrawChart after that. Any help would be appreciated
I think that it's likely (and I'm guessing because I can't see your code) that your chart data source isn't returning a reference to a datapoint which is part of the chart, but instead generating a new datapoint object each time you request one.
In order to cope with this you can request the data points from the chart itself, via the dataSeries property on SChartSeries objects.
The following delegate method should perform the selection you require.
- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
{
// Selection details
NSInteger dataPointIndex = dataPoint.index;
BOOL selected = dataPoint.selected;
for (SChartSeries *chartSeries in chart.series) {
// If only one data point in the series can be selected at once, then deselect the rest
if(!series.togglePointSelection && selected) {
for(SChartDataPoint *dp in chartSeries.dataSeries.dataPoints) {
dp.selected = NO;
}
}
// Find the data point and perform the selection
SChartDataPoint *dp = chartSeries.dataSeries.dataPoints[dataPointIndex];
dp.selected = selected;
}
}
Hope that helps.
You should be able to set .selected on the datapoints and customise the series.style.selectedPointStyle properties to display points how you wish :)