我有一个html页面来显示三个地理图,但是我不知道如何将功能分组在一起,所以我可以缩短代码而不重复(并且不确定是否可能)
例如我有这些重复的功能(3个功能有3个图表)
这是地图上不同的颜色
//assign color to colorValues
var colorNames = [];
colorValues.forEach(function(value) {
if (value <= 1) {
//1(E)PR framework legislation in place//
colorNames.push('#ffff57');
} else if ((value > 1) && (value <= 2)) {
//2(E)PR legislation in planning//
colorNames.push('#ffff9b');
} else if ((value > 2) && (value <= 3)) {
//3//Alternative model with producer funding
colorNames.push('#3FE5C9');
} else if ((value > 3) && (value <= 4)) {
//4// Alternative model – not producer funded
colorNames.push('#B97A57');
} else if ((value > 4) && (value <= 5)) {
//5// Competing organisation model
colorNames.push('#85C9F3');
} else if ((value > 5) && (value <= 6)) {
//6//Competing organisation model with coordination centre
colorNames.push('#3DA9EC');
} else if ((value > 6) && (value <= 7)) {
//7/ Competing organisation model with eco-tax back-up
colorNames.push('#DFA6FF');
} else if ((value > 7) && (value <= 8)) {
//8 Different EPR models by product category or other criteria
colorNames.push('#99F1E2');
} else if ((value > 8) && (value <= 9)) {
//9 None - but municipalities responsible for sep. collection
colorNames.push('#9edae5');
} else if ((value > 9) && (value <= 10)) {
//10 None - but other obligations for producers
colorNames.push('#d1d19d');
} else if ((value > 10) && (value <= 11)) {
//11 Other model
colorNames.push('#9edae5');
} else if ((value > 11) && (value <= 12)) {
//12 Recycler centric model
colorNames.push('#9edae5');
} else if ((value > 12) && (value <= 13)) {
//13 Single organisation model
colorNames.push('#98df8a');
} else if ((value > 15) && (value <= 16)) {
//16 under other jurisdiction
colorNames.push('#e2dace');
} else {
colorNames.push('#ffaf87');
}
});
这是针对工具提示的
var view1 = new google.visualization.DataView(data1);
view1.setColumns([16, 15,
{
type: 'string',
role: 'tooltip',
properties: {
html: true
},
calc: function(dt, row) {
var country = dt.getFormattedValue(row, 5)
var policy = dt.getFormattedValue(row, 6)
var dataname = dt.getFormattedValue(row, 8)
var dropname = dt.getFormattedValue(row, 9)
var formatter = new google.visualization.DateFormat({
pattern: "MMMM yyyy"
});
var startdate = formatter.formatValue(dt.getValue(row, 10));
//var startdate = dt.getFormattedValue(row, 10)
var comment = dt.getFormattedValue(row, 12)
//colorValues.push(dt.getFormattedValue(row, 6))
if (dropname != 'EPR policy not in place') {
return '<br><div id="country">' + country + " - " + policy + '<br><br></div> ' +
'<div id="header1">Dominant (E)PR policy model:<br></div>' +
'<div id="dropname">' + dropname + '<br><br></div>' +
'<div id ="header2">Since : </div><div id="date">' + startdate + '</div><br><br><br>' +
'<div id ="comment">' + comment + '<\/div>'
} else {
return '<br><div id="country">' + country + " - " + policy + '<br><br></div> ' +
'<div id="header1">Dominant (E)PR policy model:<br></div>' +
'<div id="dropname">' + dropname + '<br><br></div>'
}
},
}
]);
这是图表属性
var options1 = {
colorAxis: {
colors: colorNames,
values: colorValues
},
backgroundColor: {
fill: '#FFF'
},
datalessRegionColor: '#F5F0E7',
displayMode: 'regions',
legend: 'none',
enableRegionInteractivity: 'true',
resolution: 'countries',
//sizeAxis: {minValue: 1, maxValue:1,minSize:10, maxSize: 10},
region: 'null',
keepAspectRatio: false,
width: 800,
height: 480,
tooltip: {
isHtml: 'true',
textStyle: {
color: '#444444'
},
showTitle: false
}
};
,完整的代码是here
是否可以将它们组合在一起形成多个图表?
感谢您的帮助。
答案 0 :(得分:1)
确保有可能。
实际上,唯一的区别是图表需要使用的java -javaagent:./agenttest/target/agent-test-1.0-SNAPSHOT-jar-with-dependencies.jar -cp ./agent-consumer/out/production/agent-consumer/ com.dvelopp.agentconsumer.Test
com.dvelopp.agenttest.Main
java.util.stream.FindOps$FindSink$OfRef$$Lambda$13/0x0000000800063440
java.util.stream.FindOps$FindSink$OfRef$$Lambda$12/0x0000000800063040
java.util.stream.FindOps$FindSink$OfRef$$Lambda$11/0x0000000800062c40
java.util.stream.FindOps$FindSink$OfRef$$Lambda$10/0x0000000800062840
jdk.internal.module.DefaultRoots$$Lambda$9/0x0000000800062440
java.util.stream.Collectors$$Lambda$8/0x0000000800062040
java.util.stream.Collectors$$Lambda$7/0x0000000800061c40
java.util.stream.Collectors$$Lambda$6/0x0000000800061840
java.util.stream.Collectors$$Lambda$5/0x0000000800061440
jdk.internal.module.DefaultRoots$$Lambda$4/0x0000000800061040
jdk.internal.module.DefaultRoots$$Lambda$3/0x0000000800060c40
jdk.internal.module.DefaultRoots$$Lambda$2/0x0000000800060840
java.lang.invoke.LambdaForm$MH/0x0000000800060440
jdk.internal.module.DefaultRoots$$Lambda$1/0x0000000800060040
sun.instrument.InstrumentationImpl$1
sun.security.util.Debug
java.security.SecureClassLoader$DebugHolder
java.security.BasicPermissionCollection
java.lang.RuntimePermission
java.security.UnresolvedPermission
java.security.AllPermission
java.io.FilePermissionCollection$1
java.io.FilePermissionCollection
java.security.Permissions$1
sun.security.util.FilePermCompat
java.io.FilePermission$1
jdk.internal.misc.JavaIOFilePermissionAccess
java.io.FilePermission
sun.net.www.MessageHeader
sun.net.www.protocol.file.FileURLConnection
sun.net.www.URLConnection
java.net.URLConnection
java.security.Permissions
java.security.PermissionCollection
java.security.SecureClassLoader$1
java.security.SecureClassLoader$CodeSourceKey
sun.nio.ByteBuffered
java.lang.Package$VersionInfo
java.lang.Package
java.lang.NamedPackage
java.util.jar.Attributes$Name
sun.nio.cs.StandardCharsets$Cache
sun.nio.cs.StandardCharsets$Aliases
sun.util.PreHashedMap
java.util.jar.Manifest$FastInputStream
java.util.jar.Attributes
java.lang.StringCoding$Result
jdk.internal.loader.URLClassPath$JarLoader$2
jdk.internal.loader.Resource
java.util.zip.ZipFile$InflaterCleanupAction
java.util.zip.Inflater$InflaterZStreamRef
java.util.zip.Inflater
java.util.zip.ZipFile$ZipFileInflaterInputStream
java.util.zip.InflaterInputStream
java.util.zip.ZipFile$ZipFileInputStream
java.util.jar.JarFile$JarFileEntry
java.util.jar.JarEntry
java.util.zip.ZipEntry
java.util.jar.JarFile$1
jdk.internal.util.jar.JarIndex
java.nio.DirectLongBufferU
java.nio.LongBuffer
java.nio.Bits$1
jdk.internal.misc.JavaNioAccess$BufferPool
java.util.concurrent.atomic.AtomicLong
java.nio.Bits
java.nio.DirectByteBuffer
java.nio.MappedByteBuffer
sun.nio.ch.DirectBuffer
jdk.internal.perf.PerfCounter$CoreCounters
jdk.internal.perf.Perf
jdk.internal.perf.Perf$GetPerfAction
jdk.internal.perf.PerfCounter
java.util.zip.ZipUtils
java.util.zip.ZipFile$Source$End
java.io.FileCleanable
[Ljava.lang.invoke.MemberName;
[Ljava.lang.invoke.VarHandle$AccessMode;
java.lang.invoke.VarHandle$AccessMode
[Ljava.lang.invoke.VarHandle$AccessType;
java.lang.invoke.VarHandle$AccessType
java.lang.invoke.VarForm
java.lang.invoke.VarHandleGuards
jdk.internal.util.Preconditions$1
java.lang.invoke.VarHandle$1
java.lang.invoke.VarHandleInts$FieldInstanceReadWrite
java.lang.invoke.VarHandleInts$FieldInstanceReadOnly
java.lang.invoke.VarHandles
java.util.concurrent.atomic.AtomicBoolean
java.io.RandomAccessFile$2
jdk.internal.misc.JavaIORandomAccessFileAccess
java.io.RandomAccessFile
java.io.DataInput
java.io.DataOutput
java.nio.file.attribute.FileTime
[Ljava.util.concurrent.TimeUnit;
java.util.concurrent.TimeUnit
sun.nio.fs.UnixFileAttributes$UnixAsBasicFileAttributes
[Lsun.nio.fs.NativeBuffer;
sun.nio.fs.NativeBuffer$Deallocator
sun.nio.fs.NativeBuffer
java.util.IdentityHashMap$KeySet
java.util.IdentityHashMap
jdk.internal.misc.TerminatingThreadLocal$1
sun.nio.fs.NativeBuffers$1
sun.nio.fs.NativeBuffers
sun.nio.fs.UnixFileAttributeViews$Basic
sun.nio.fs.AbstractBasicFileAttributeView
sun.nio.fs.DynamicFileAttributeView
sun.nio.fs.UnixFileAttributeViews
java.nio.file.attribute.BasicFileAttributeView
java.nio.file.attribute.FileAttributeView
java.nio.file.attribute.AttributeView
java.nio.file.Files
[Ljava.nio.file.LinkOption;
[Ljava.nio.file.CopyOption;
java.nio.file.LinkOption
java.nio.file.CopyOption
java.net.URI$Parser
java.nio.file.FileSystems$DefaultFileSystemHolder$1
java.nio.file.FileSystems$DefaultFileSystemHolder
[Ljava.nio.charset.CoderResult;
java.nio.charset.CoderResult
java.nio.HeapCharBuffer
java.nio.CharBuffer
java.lang.Readable
jdk.internal.misc.TerminatingThreadLocal
[Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;
java.lang.ThreadLocal$ThreadLocalMap$Entry
java.lang.ThreadLocal$ThreadLocalMap
sun.nio.fs.UnixMountEntry
jdk.internal.misc.JavaUtilZipFileAccess
java.util.zip.ZipFile
java.util.zip.ZipConstants
jdk.internal.loader.URLClassPath$JarLoader
jdk.internal.loader.URLClassPath$FileLoader
jdk.internal.loader.URLClassPath$Loader
java.util.concurrent.ConcurrentHashMap$ValueIterator
java.util.Enumeration
java.util.concurrent.ConcurrentHashMap$ValuesView
jdk.internal.loader.URLClassPath$3
java.security.PrivilegedExceptionAction
sun.util.locale.InternalLocaleBuilder$CaseInsensitiveChar
sun.util.locale.InternalLocaleBuilder
sun.util.locale.LocaleUtils
sun.util.locale.LocaleObjectCache$CacheEntry
sun.util.locale.BaseLocale$Key
sun.util.locale.BaseLocale$Cache
sun.util.locale.BaseLocale
java.util.Locale$Cache
sun.util.locale.LocaleObjectCache
java.util.Locale
sun.net.util.URLUtil
[Lsun.instrument.TransformerManager$TransformerInfo;
sun.instrument.TransformerManager$TransformerInfo
sun.instrument.TransformerManager
java.util.ArrayDeque$DeqIterator
java.lang.ClassLoader$NativeLibrary
java.lang.ClassLoader$2
sun.instrument.InstrumentationImpl
java.lang.instrument.Instrumentation
java.lang.InternalError
jdk.internal.module.ModuleBootstrap$SafeModuleFinder
jdk.internal.module.IllegalAccessLogger
jdk.internal.module.ModuleBootstrap$2
jdk.internal.module.IllegalAccessLogger$Builder
[Ljdk.internal.module.IllegalAccessLogger$Mode;
jdk.internal.module.IllegalAccessLogger$Mode
java.lang.ModuleLayer$Controller
jdk.internal.module.ServicesCatalog$ServiceProvider
java.util.concurrent.CopyOnWriteArrayList
java.util.concurrent.ConcurrentHashMap$ForwardingNode
jdk.internal.module.ModuleLoaderMap$Mapper
jdk.internal.module.ModuleLoaderMap
java.util.Collections$UnmodifiableRandomAccessList
java.util.Collections$UnmodifiableList
[Ljava.lang.module.ResolvedModule;
java.lang.module.ResolvedModule
java.util.Collections$UnmodifiableCollection$1
java.util.LinkedHashSet
java.util.HashMap$ValueIterator
java.util.HashMap$Values
java.lang.ModuleLayer
java.lang.module.ModuleFinder$1
[Ljava.nio.file.Path;
[Ljava.lang.Iterable;
[Ljava.nio.file.Watchable;
java.nio.file.Path
java.nio.file.Watchable
java.lang.module.Resolver
java.lang.module.Configuration
java.util.ImmutableCollections$Set12$1
java.util.stream.FindOps$FindOp
java.util.stream.FindOps$FindSink$OfRef
java.util.stream.FindOps$FindSink
java.util.stream.FindOps
java.util.stream.ReferencePipeline$2$1
java.util.stream.ReferencePipeline$3$1
java.util.stream.Sink$ChainedReference
java.util.stream.ReduceOps$3ReducingSink
java.util.stream.ReduceOps$Box
java.util.stream.ReduceOps$AccumulatingSink
java.util.stream.TerminalSink
java.util.stream.Sink
java.util.function.Consumer
java.util.stream.ReduceOps$3
java.util.stream.ReduceOps$ReduceOp
java.util.stream.TerminalOp
java.util.stream.ReduceOps
java.util.function.BinaryOperator
java.util.function.BiFunction
java.util.function.BiConsumer
java.lang.invoke.DirectMethodHandle$Interface
java.lang.invoke.DirectMethodHandle$Constructor
java.util.stream.Collectors$CollectorImpl
java.util.stream.Collector
java.util.Collections$UnmodifiableSet
java.util.Collections$UnmodifiableCollection
java.util.RegularEnumSet
java.util.EnumSet
[Ljava.util.stream.Collector$Characteristics;
java.util.stream.Collector$Characteristics
java.util.stream.Collectors
jdk.internal.org.objectweb.asm.FieldWriter
jdk.internal.org.objectweb.asm.FieldVisitor
java.util.stream.ReferencePipeline$3
[Ljava.util.stream.StreamShape;
java.util.stream.StreamShape
java.util.stream.ReferencePipeline$2
java.util.stream.ReferencePipeline$StatelessOp
jdk.internal.misc.InnocuousThread$2
jdk.internal.misc.InnocuousThread$3
[Ljava.security.ProtectionDomain;
jdk.internal.misc.InnocuousThread
jdk.internal.ref.CleanerFactory$1$1
jdk.internal.ref.CleanerImpl$CleanerCleanable
jdk.internal.ref.CleanerImpl$SoftCleanableRef
jdk.internal.ref.SoftCleanable
jdk.internal.ref.CleanerImpl$WeakCleanableRef
jdk.internal.ref.WeakCleanable
jdk.internal.ref.CleanerImpl$PhantomCleanableRef
jdk.internal.ref.PhantomCleanable
java.lang.ref.Cleaner$Cleanable
jdk.internal.ref.CleanerImpl
java.lang.ref.Cleaner$1
java.lang.ref.Cleaner
jdk.internal.ref.CleanerFactory$1
java.util.concurrent.ThreadFactory
jdk.internal.ref.CleanerFactory
java.util.ArrayList$Itr
java.lang.invoke.InvokerBytecodeGenerator$CpPatch
java.lang.invoke.LambdaFormBuffer
java.lang.invoke.LambdaFormEditor$Transform
java.lang.invoke.LambdaFormEditor
java.lang.invoke.DelegatingMethodHandle$Holder
java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle
java.lang.invoke.DelegatingMethodHandle
sun.invoke.util.Wrapper$1
java.lang.invoke.DirectMethodHandle$Accessor
java.lang.invoke.DirectMethodHandle$1
sun.invoke.empty.Empty
sun.invoke.util.VerifyType
java.lang.invoke.BoundMethodHandle$Species_L
java.lang.NoSuchFieldException
java.util.ImmutableCollections$ListItr
java.util.ListIterator
java.lang.invoke.SimpleMethodHandle
[Ljava.lang.invoke.BoundMethodHandle$SpeciesData;
[Ljava.lang.invoke.ClassSpecializer$SpeciesData;
java.lang.invoke.BoundMethodHandle$Specializer$Factory
java.lang.invoke.ClassSpecializer$Factory
java.util.ImmutableCollections$SubList
java.lang.invoke.BoundMethodHandle$SpeciesData
java.lang.invoke.ClassSpecializer$SpeciesData
java.lang.invoke.ClassSpecializer$1
java.util.function.Function
java.lang.invoke.BoundMethodHandle$Specializer
java.lang.invoke.ClassSpecializer
java.lang.invoke.BoundMethodHandle
java.lang.invoke.InnerClassLambdaMetafactory$1
[[I
java.lang.invoke.InnerClassLambdaMetafactory$ForwardingMethodGenerator
java.lang.invoke.TypeConvertingMethodAdapter
jdk.internal.org.objectweb.asm.AnnotationWriter
jdk.internal.org.objectweb.asm.AnnotationVisitor
jdk.internal.org.objectweb.asm.Frame
jdk.internal.org.objectweb.asm.Label
jdk.internal.org.objectweb.asm.MethodWriter
jdk.internal.org.objectweb.asm.MethodVisitor
[Ljava.util.concurrent.ConcurrentHashMap$CounterCell;
[Ljdk.internal.org.objectweb.asm.Item;
jdk.internal.org.objectweb.asm.Item
jdk.internal.org.objectweb.asm.ByteVector
jdk.internal.org.objectweb.asm.ClassWriter
jdk.internal.org.objectweb.asm.ClassVisitor
sun.invoke.util.BytecodeDescriptor
java.lang.invoke.InfoFromMemberName
java.lang.invoke.MethodHandleInfo
[Ljdk.internal.org.objectweb.asm.Type;
jdk.internal.org.objectweb.asm.Type
java.lang.invoke.InnerClassLambdaMetafactory
java.lang.invoke.AbstractValidatingLambdaMetafactory
java.lang.invoke.MethodHandleImpl$1
jdk.internal.misc.JavaLangInvokeAccess
java.lang.invoke.Invokers$Holder
java.lang.invoke.BootstrapMethodInvoker
java.util.function.Predicate
java.lang.WeakPairMap$Pair$Lookup
java.lang.WeakPairMap$Pair
java.lang.WeakPairMap
java.lang.Module$ReflectionData
java.lang.invoke.InvokerBytecodeGenerator$2
java.lang.invoke.InvokerBytecodeGenerator
[Ljava.lang.invoke.MethodHandleImpl$Intrinsic;
java.lang.invoke.MethodHandleImpl$Intrinsic
java.lang.invoke.LambdaForm$Holder
[[Ljava.lang.invoke.LambdaForm$Name;
[[Ljava.lang.Object;
[Ljava.lang.Cloneable;
[Ljava.lang.invoke.LambdaForm$Name;
java.lang.invoke.LambdaForm$Name
[Ljava.lang.invoke.LambdaForm$BasicType;
java.lang.invoke.LambdaForm$BasicType
java.lang.NoSuchMethodException
[Ljava.lang.invoke.LambdaForm$Kind;
java.lang.invoke.LambdaForm$Kind
java.lang.invoke.Invokers
java.lang.invoke.MethodHandleImpl
sun.invoke.util.ValueConversions
java.lang.invoke.DirectMethodHandle$Holder
[Ljava.lang.invoke.LambdaForm$NamedFunction;
java.lang.invoke.LambdaForm$NamedFunction
[Ljava.lang.invoke.LambdaForm;
[Lsun.invoke.util.Wrapper;
sun.invoke.util.Wrapper$Format
sun.invoke.util.Wrapper
sun.invoke.util.VerifyAccess
[Ljava.lang.invoke.MethodHandle;
java.lang.reflect.ReflectPermission
java.security.BasicPermission
java.security.Permission
java.security.Guard
java.lang.invoke.MemberName$Factory
java.lang.invoke.MethodHandles
[Ljava.lang.ref.SoftReference;
java.lang.invoke.MethodTypeForm
java.lang.Void
java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry
[Ljava.lang.invoke.MethodType;
java.lang.invoke.MethodType$ConcurrentWeakInternSet
java.lang.invoke.MethodHandles$Lookup
java.lang.invoke.LambdaMetafactory
[Ljava.util.stream.StreamOpFlag;
jdk.internal.reflect.DelegatingMethodAccessorImpl
jdk.internal.reflect.NativeMethodAccessorImpl
[Ljava.lang.annotation.Annotation;
sun.reflect.annotation.AnnotationParser
java.util.HashMap$EntryIterator
java.util.HashMap$EntrySet
java.lang.Class$3
java.lang.PublicMethods$Key
java.lang.PublicMethods$MethodList
[Ljava.lang.reflect.Method;
java.util.EnumMap$1
的ID。
请参阅以下工作片段,
在这里,我正在使用变量来更改java.lang.invoke.MethodHandleNatives
java.lang.invoke.ResolvedMethodName
java.lang.invoke.MemberName
java.lang.invoke.VarHandle
java.lang.invoke.DirectMethodHandle
java.lang.invoke.MethodHandle
jdk.internal.reflect.CallerSensitive
java.lang.annotation.Annotation
jdk.internal.reflect.UnsafeStaticFieldAccessorImpl
jdk.internal.reflect.UnsafeFieldAccessorImpl
jdk.internal.reflect.FieldAccessorImpl
jdk.internal.reflect.FieldAccessor
jdk.internal.reflect.ConstantPool
jdk.internal.reflect.DelegatingClassLoader
jdk.internal.reflect.ConstructorAccessorImpl
jdk.internal.reflect.ConstructorAccessor
jdk.internal.reflect.MethodAccessorImpl
jdk.internal.reflect.MethodAccessor
jdk.internal.reflect.MagicAccessorImpl
java.lang.reflect.Constructor
java.lang.reflect.Method
java.lang.reflect.Executable
java.lang.reflect.Parameter
java.lang.reflect.Field
java.lang.reflect.Member
java.lang.reflect.AccessibleObject
java.lang.Module
java.util.Properties
java.util.Hashtable
java.util.Dictionary
java.util.Map
java.lang.ThreadGroup
java.lang.Thread$UncaughtExceptionHandler
java.lang.Thread
java.lang.Runnable
java.lang.ref.Finalizer
java.lang.ref.PhantomReference
java.lang.ref.FinalReference
java.lang.ref.WeakReference
java.lang.ref.SoftReference
java.lang.ref.Reference
java.lang.IllegalMonitorStateException
java.lang.StackOverflowError
java.lang.OutOfMemoryError
java.lang.VirtualMachineError
java.lang.ArrayStoreException
java.lang.ClassCastException
java.lang.NoClassDefFoundError
java.lang.LinkageError
java.lang.ClassNotFoundException
java.lang.ReflectiveOperationException
java.security.SecureClassLoader
java.security.AccessControlContext
java.security.ProtectionDomain
java.lang.SecurityManager
java.lang.RuntimeException
java.lang.Exception
java.lang.ThreadDeath
java.lang.Error
java.lang.Throwable
java.lang.System
java.lang.ClassLoader
java.lang.Cloneable
java.lang.Class
java.lang.reflect.Type
java.lang.reflect.GenericDeclaration
java.lang.reflect.AnnotatedElement
java.lang.String
java.lang.CharSequence
java.lang.Comparable
java.io.Serializable
java.lang.Object
[J
[I
[S
[B
[D
[F
[C
[Z
Hello World!
-> <div>
的ID
所有查询都调用同一函数-> <div>
编辑
而不是增加div的ID,而是将其传递给函数。
这样可以确保数据显示在正确的图表上。
'colormap' + id
和...
handleQueryResponseTR
请参阅以下更新的代码段...
function handleQueryResponseTR(response1, divId) {
...
var chart1 = new google.visualization.GeoChart(document.getElementById(divId));