在highcharts中按名称或ID删除系列

时间:2014-02-24 05:21:45

标签: javascript highcharts

无论如何要删除名称或ID的系列?我的意思是可以通过this.remove()

删除系列

var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--) {
    chart.series[i].remove();
}

但按名称说,series_name.remove()是否可能?

5 个答案:

答案 0 :(得分:12)

好吧,我不知道当时是否可能,但现在你在get对象中有一个chart函数可以传递id并检索chart中的元素。

例如:

var chart = new Highcharts.Chart({    
    chart: { renderTo: 'container' },
    series: [
      {
        id: 'series-1', 
        data: [1,2,3,4,5,6,7,8,9]
      },
      {
        id: 'series-2',
        data: [9,8,7,6,5,4,3,2,1]
      }
    ]
});

//Remove the 'series-2'
chart.get('series-2').remove();

Working example in jsfiddle

答案 1 :(得分:10)

好的,我自己找到了。我在div的隐藏字段中发送系列名称,当我单击删除按钮时,我正在检查名称是否与系列匹配,如果匹配,我将其删除。

var chart = $('#container').highcharts();
                var seriesLength = chart.series.length;
                for(var i = seriesLength - 1; i > -1; i--)
                {
                    //chart.series[i].remove();
                    if(chart.series[i].name ==document.getElementById("series_name").value)
                        chart.series[i].remove();
                }

答案 2 :(得分:1)

这需要更多的可见性,因为这是相当笨拙的。您可能只是遍历该系列并检查.name以及#34;传递的名称"而不是扫描文档" series_name"。

确实应该有一个chart.remove(系列)(不仅仅是索引,因为在删除索引后会重新映射索引)。

答案 3 :(得分:1)

这两个简单的解决方案对我有用。

更新:我意识到我误解了这个问题。这些解决方案删除了​​所有的内容。

使用jQuery隐藏它

$(function () {
  // Build the chart.
  $('#volume_pie_chart').highcharts({
      // Some configuration code...
    })

    // Hide the legend.
    $('.highcharts-legend').hide()
});

定位图例,以便我们看不到它

...
},
legend: {
    x: 9999, // Make the legend invisible.
    y: 9999
},
...

答案 4 :(得分:0)

HighCharts 6.x.x

您可以使用javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:963) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1342) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1369) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1353) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254) at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at com.flinto.core.admin.WebClientUtility.fetchPayuStatus(WebClientUtility.java:377) at com.flinto.web.controller.CreateOrderAdminController.updateOrderPaymentStatus(CreateOrderAdminController.java:849) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.flinto.web.utils.WebCommon.urlRedirectByAccessRole(WebCommon.java:402) at com.flinto.web.filter.UrlRedirectionFilter.doFilter(UrlRedirectionFilter.java:37) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.flinto.web.filter.ApexDomainRedirectFilter.doFilter(ApexDomainRedirectFilter.java:37) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:652) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:883) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:756) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2391) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:482) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:944) ... 92 more 方法按ID获取Series对象。下面是文档链接 - https://api.highcharts.com/class-reference/Highcharts.Chart#get

系列还有class BankAccount(models.Model): SAVINGS = 'saving' CURRENT = 'current' TYPE = ( (SAVINGS,'Saving'), (CURRENT,'Current') ) type = models.CharField(max_length=20, choices=TYPE, default=SAVINGS) bank_name = models.CharField(max_length=200) account_number = models.IntegerField() balance = models.DecimalField(max_digits=10, decimal_places=2) def __str__(self): """returns the model as string.""" return self.bank_name def __str__(self): """returns the model as string.""" return self.type serializers.py class BankAccountSerializer(serializers.ModelSerializer): class Meta: model = BankAccount fields = '__all__' views.py class BankAccountView(APIView): def get_object(self, pk): try: return BankAccount.objects.get(pk=pk) except BankAccount.DoesNotExist: raise Http404 def get(self, request, format=None): accounts = BankAccount.objects.all() serializer = BankAccountSerializer(accounts, many=True) return Response(serializer.data) def post(self, request, format=None): serializer = BankAccountSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) def put(self, request, format=None): data = json.loads(request.body) pk = data['id'] action = data['action'] if action == 'delete': return self.deleteItem(pk) account = self.get_object(pk) serializer = BankAccountSerializer(account, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) def deleteItem(self, pk): account = self.get_object(pk) account.delete() return Response(status=status.HTTP_204_NO_CONTENT) 方法从图表中删除系列 - https://api.highcharts.com/class-reference/Highcharts.Series#remove