def compareChart(currentWeek, students, names, averageRank): if not os.path.exists(chart_folder): os.makedirs(chart_folder) raw_options['chart']['height'] = 800 options = copy.deepcopy(raw_options) options['title']['text'] = 'Normalized Rank Comparison Chart' options['yAxis']['title']['text'] = 'Normalized Rank' options['xAxis']['title']['text'] = 'Week' chart = Highchart() chart.set_dict_options(options) series = [] for student in students: if not student.is_active: continue name = names[student.user_name] data = [] for week in range(1, currentWeek + 1): rank = averageRank[week-1].get(student.user_name) if rank is not None: point = [week, rank] data.append(point) series.append({'name': name, 'data': data}) chart.add_data_set(data, 'spline', name, marker={'enabled': True}) #options['series'] = series chart.save_file(chart_folder + 'compare')
def save_map(): chart = Highchart() chart.set_options('chart', {'inverted': True}) options = { 'title': { 'text': 'LoadBoy 接口负载图' }, 'subtitle': { 'text': '响应时间/吞吐量/线程数' }, 'xAxis': { 'reversed': False, 'title': { 'enabled': True, 'text': '响应时间' }, 'labels': { 'formatter': 'function () {\ return this.value + " t/s";\ }' }, 'maxPadding': 0.05, 'showLastLabel': True }, 'yAxis': { 'title': { 'text': '线程数' }, 'labels': { 'formatter': "function () {\ return this.value + '';\ }" }, 'lineWidth': 2 }, 'legend': { 'enabled': False }, 'tooltip': { 'headerFormat': '<b>{series.name}</b><br/>', 'pointFormat': '' } } chart.set_dict_options(options) global rt2 global tps global t_num tps_data = list(zip(tps, t_num)) chart.add_data_set(tps_data, 'spline', 'tps', marker={'enabled': False}) rt_data = list(zip(rt2, t_num)) chart.add_data_set(rt_data, 'line', 'rt', marker={'enabled': False}) chart.save_file()
def make_chart_daily_exposure(stats): chart = Highchart() options = { 'chart': { 'zoomType': 'x' }, 'title': { 'text': 'End of day exposure' }, 'xAxis': { 'type': 'datetime' }, 'yAxis': { 'title': { 'text': 'Exposure' } }, 'legend': { 'enabled': False } } chart.set_dict_options(options) timestamps = stats.index.astype(np.int64) // 1000000 plot_data = np.dstack( (timestamps, stats["day_end_exposure"].values))[0].tolist() chart.add_data_set(plot_data, 'area', 'Exposure') return chart
def make_chart_daily_max_long_short(stats): chart = Highchart() options = { 'chart': { 'zoomType': 'x' }, 'title': { 'text': 'Max Long/Short intra day' }, 'xAxis': { 'type': 'datetime' }, 'yAxis': { 'title': { 'text': '$' } }, 'legend': { 'enabled': False } } chart.set_dict_options(options) timestamps = stats.index.astype(np.int64) // 1000000 long_data = np.dstack((timestamps, stats["max_long"].values))[0].tolist() chart.add_data_set(long_data, 'column', 'Max Long') short_data = np.dstack( (timestamps, -stats["max_short"].values))[0].tolist() chart.add_data_set(short_data, 'column', 'Max Short') return chart
def make_chart_realized_pnl(stats): chart = Highchart() options = { 'chart': { 'zoomType': 'x' }, 'title': { 'text': 'Realized Cumulative Profit and Loss' }, 'xAxis': { 'type': 'datetime' }, 'yAxis': { 'title': { 'text': 'Realized P/L' } }, 'legend': { 'enabled': False } } chart.set_dict_options(options) timestamps = stats.index.astype(np.int64) // 1000000 plot_data = np.dstack( (timestamps, stats["realized_pnl"].values))[0].tolist() chart.add_data_set(plot_data, 'line', 'PnL') return chart
def make_chart_max_drawdown(stats): chart = Highchart() options = { 'chart': { 'zoomType': 'x' }, 'title': { 'text': 'Max Drawdown' }, 'xAxis': { 'type': 'datetime' }, 'yAxis': { 'title': { 'text': 'Daily P/L' } }, 'legend': { 'enabled': False } } chart.set_dict_options(options) timestamps = stats.index.astype(np.int64) // 1000000 plot_data = np.dstack( (timestamps, stats["max_drawdown"].values))[0].tolist() chart.add_data_set(plot_data, 'column', 'Max Drawdown') return chart
def create_line_chart(categories, values, title, filename, charttype, orientation, axisreverse, stack): chart = Highchart() options = { 'chart': { 'type': charttype }, 'title': { 'text': title }, 'xAxis': { 'categories': categories, 'labels': { 'rotation': 45 } }, 'yAxis': { 'title': { 'text': '#Cases' }, 'stackLabels': { 'enabled': False, 'verticalAlign': 'top', 'y': 100 } }, 'plotOptions': { 'series': { 'dataLabels': { 'enabled': True }, 'stacking': 'normal' } }, 'legend': { 'enabled': True }, 'tooltip': { 'enabled': True, 'shared': True, 'formatter': "function(){ var s = '<b>'+ this.x +'</b>'; var s1=''; var sum = 0; $.each(this.points, function(i, point) { s1 += '<br/><b>'+ point.series.name +'</b>: '+ point.y ; sum += point.y; }); s += '<br/><b>Total</b>: '+sum ; return s+s1;}" } } chart.set_dict_options(options) print(options) colors = ['#1A5276', '#6E2C00', '#2C3E50', '#45B39D'] keys = list(values.keys()) for series in keys: data = values[series] chart.add_data_set(data, charttype, series, marker={'enabled': True}, color=colors[keys.index(series)]) print(filename) chart.save_file(filename)
def timeline_python_highcharts(): """Return filename of plot of the damped_vibration function.""" H = Highchart() timeline_data = pd.read_csv('timeline.txt') options = { 'chart': { 'type': 'columnrange', 'inverted': True, 'zoomType': 'y' }, 'title': { 'text': 'BepiTimeline Test' }, 'xAxis': { 'categories': list(set(timeline_data['Instrument'].values.tolist())) }, 'yAxis': { 'type': 'datetime' }, 'tooltip': { 'formatter': "function () {return Highcharts.dateFormat('%e %B %H:%M', this.point.low) + ' - ' + Highcharts.dateFormat('%e %B %H:%M', this.point.high);}" }, 'plotOptions': { 'columnrange': { 'grouping': False } } } H.set_dict_options(options) grouped = timeline_data.groupby('Instrument') grouped = [grouped.get_group(x) for x in grouped.groups] for level, frame in enumerate(grouped): df = {} df['name'] = frame['Instrument'].values[0] df['data'] = [] for row in frame.itertuples(): block = {} block['x'] = level st = dt.strptime(row[2], '%Y-%m-%d %H:%M') st = int((st-dt(1970,1,1)).total_seconds()*1000) en = dt.strptime(row[3], '%Y-%m-%d %H:%M') en = int((en-dt(1970,1,1)).total_seconds()*1000) block['low'] = st block['high'] = en df['data'].append(block) H.add_data_set(df['data'], 'columnrange', df['name'] ) print(H.iframe) return 0
def hc_line_time_series(data, title, y_title=None, theme=None, xl_dates=False): """Plots a 2d array of times and data points.""" # Convert Excel dates to datetimes if necessary if xl_dates: to_date = get_type_converter("var", "datetime") data = [(to_date(d), v) for d, v in data] H = Highchart() H.set_options('chart', { 'zoomType': 'x' }) H.set_options('xAxis', { 'type': 'datetime' }) H.set_options('yAxis', { 'title': { 'text': y_title or "Values" } }) H.set_options('title', { 'text': title or "Time Series" }) H.set_options('legend', { 'enabled': False }) H.add_data_set(data, 'area') H.set_options('plotOptions', { 'area': { 'fillColor': { 'linearGradient': { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 1}, 'stops': [ [0, "Highcharts.getOptions().colors[0]"], [1, "Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')"] ]}, 'marker': { 'radius': 2 }, 'lineWidth': 1, 'states': { 'hover': { 'lineWidth': 1 } }, 'threshold': None } }) return hc_plot(H, title, theme)
def generateCharts(currentWeek, students, names, averageRank, averageToken): if not os.path.exists(chart_folder): os.makedirs(chart_folder) raw_options['chart']['height'] = 500 options = copy.deepcopy(raw_options) options['yAxis'] = [{ 'min' : -1, 'max' : 1, 'reversed': True, 'title': { 'text': 'Normalized Rank' }, 'labels': { 'formatter': "function () {\ return this.value;\ }" }, 'lineWidth': 2 }, { 'reversed': True, 'title': { 'text': 'Normalized Token' }, 'labels': { 'formatter': "function () {\ return this.value;\ }" }, 'lineWidth': 2, 'opposite': True }, ] options['xAxis']['title']['text'] = 'Week' for student in students: if not student.is_active: continue chart = Highchart() options['title']['text'] = names[student.user_name] options['chart']['renderTo'] = 'container_' + student.user_name chart.set_dict_options(options) rank_data = [] token_data = [] for week in range(1, currentWeek + 1): rank = averageRank[week-1].get(student.user_name) token = averageToken[week-1].get(student.user_name) if rank is not None and token is not None: point = [week, rank] rank_data.append(point) point = [week, token] token_data.append(point) chart.add_data_set(rank_data, 'spline', 'Normalized Rank', marker={'enabled': True}) chart.add_data_set(token_data, 'spline', 'Normalized Token', marker={'enabled': True}, yAxis=1) chart.save_file(chart_folder + student.user_name)
def create_graph(self, custom_begin_date, custom_end_date, quantity, time_interval): sensor_node = SensorNode(self.node_id) timestamps = self.get_begin_and_end_timestamps(custom_begin_date, custom_end_date, time_interval) line_graph = Highchart() time_label = '' sensor_node.set_measurements( self.select_measurements(timestamps[0], timestamps[1], quantity)) measurement_types = sensor_node.get_distinct_measurement_types() for m_type in measurement_types: data_list = sensor_node.create_data_list(m_type) line_graph.add_data_set( data_list, series_type='line', name=(sensor_node.get_sensor_description(m_type))) if time_interval == TimeInterval.TODAY or time_interval == TimeInterval.YESTERDAY: time_label = "'hour': '%H:%M'" elif time_interval == TimeInterval.LAST_WEEK: time_label = "'day': '%e. %b'" options = { 'title': { 'text': str(quantity) + " meetdata van bijenkast " + str(sensor_node.node_id) }, 'subtitle': { 'text': "iBee 2017-2018" }, 'xAxis': { 'type': "datetime", 'dateTimeLabelFormats': {time_label}, 'title': { 'text': "Tijd" } }, 'yAxis': { 'title': { 'text': quantity } } } line_graph.set_dict_options(options) return line_graph
def plot_2d(self): h = Highchart(width=750, height=600) options = { 'title': { 'text': 'Value Function Iteration' }, 'xAxis': { 'title': { 'text': "K - Capital Level" } }, 'yAxis': { 'title': { 'text': "Value of Capital" } }, 'tooltip': { 'crosshairs': False, 'shared': True, }, 'legend': {} } h.set_dict_options(options) for x in range(0, len(self.z_vector)): df1 = pd.DataFrame({ 'k': self.k_vector[1:], 'value': self.value_matrix[1:, [x]].flatten() }) df1 = df1[['k', 'value']] df1 = df1.values.tolist() h.add_data_set(df1, 'spline', 'z_' + str(x) + ' = ' + str(self.z_vector[x]), zIndex=1, marker={ 'fillColor': 'white', 'lineWidth': 2, 'lineColor': 'Highcharts.getOptions().colors[1]' }) html_str = h.htmlcontent.encode('utf-8') html_file = open("chart.html", "w") html_file.write(html_str) html_file.close()
def fuel_stat(request, auto_id=None, start_date=None, end_date=None): '''Stat for supply''' common = {"name": "Fuel"} # Initial-default values last_auto = models.Supply.objects.latest('id').auto start_date_init = timezone.now().date() + timezone.timedelta(days=-60) end_date_init = timezone.now().date() # get form form = forms.FuelStatForm(request.GET) if form.is_valid(): common["auto"] = form.cleaned_data['auto'] common["start_date"] = form.cleaned_data['start_date'] common["end_date"] = form.cleaned_data['end_date'] else: form = forms.FuelStatForm(initial={"auto":last_auto, "start_date":start_date_init, "end_date":end_date_init}) common["auto"] = last_auto common["start_date"] = start_date_init common["end_date"] = end_date_init # Get data Supply = models.Supply.objects.filter(auto=common["auto"]).filter(event_date__gte=common["start_date"]) \ .filter(event_date__lte=common["end_date"]).order_by('event_date').all() cum_sum = [[0, 0, 0]] # calcolo la somma, per ottenere la cumulata for supply in Supply: supply.calcStat() cum_sum.append([supply.event_date, cum_sum[-1][1]+supply.distance, cum_sum[-1][2]+supply.volume]) cum_sum.pop(0) # Highchart chart = Highchart(height = 500) chart.add_data_set([[1000*(a.event_date-datetime.date(1970,1,1)).total_seconds(), int(a.pricevolume*100)/100] for a in Supply], series_type='line', name='Prezzo (€/litro)') chart.add_data_set([[1000*(a.event_date-datetime.date(1970,1,1)).total_seconds(), int(a.consumption1*100)/100] for a in Supply], series_type='line', name='km con un litro') chart.add_data_set([[1000*(a[0]-datetime.date(1970,1,1)).total_seconds(), int(a[1]/a[2]*100)/100] for a in cum_sum], series_type='line', name='km con un litro (tendenza)') chart.set_options('xAxis', {'type': 'datetime', 'gridLineWidth': 1}) # chart.set_options('chart', {'backgroundColor':'transparent'}) chart.set_options('tooltip', {'formatter': 'default_tooltip'}) chart.set_options('title', {'text': f"Statistiche consumo {common['auto']}"}) chart.htmlcontent; chart_dict = {"header": chart.htmlheader, "content":chart.content} return render(request, 'alldoc/fuel_stat.html', {"common": common, "Supply": Supply, "form": form, "chart": chart_dict})
def renderChart(stats, bottom, left="Workflow Job"): keys = [k for k, _ in stats.items()] values = [v for _, v in stats.items()] chart = Highchart() chart.set_options("chart", {"inverted": True}) options = { "title": { "text": "{0} by {1}".format(bottom, left) }, "xAxis": { "categories": keys, "title": { "text": left }, "maxPadding": 0.05, "showLastLabel": True, }, "yAxis": { "title": { "text": bottom }, "labels": { "formatter": "function () {\ return this.value;\ }" }, "lineWidth": 2, }, "legend": { "enabled": False }, "tooltip": { "headerFormat": "<b>{series.name}</b><br/>", "pointFormat": "{point.x} : {point.y}", }, } chart.set_dict_options(options) chart.add_data_set(values, "bar") return str(chart)
def hc_basic_line(data, title, subtitle=None, y_axis=None, labels=None, theme=None): H = Highchart() H.set_options("title", { "text": title }) if subtitle: H.set_options("subtitle", { "text": subtitle }) if y_axis: H.set_options("yAxis", { "title": { "text": y_axis } }) H.set_options("legend", { "layout": "vertical", "align": "right", "verticalAlign": "middle" }) # transform the data from a list of rows to a list of columns data_t = list(zip(*data)) # Use the first column as the X axis x_axis = data_t[0] H.set_options("xAxis", { "categories": x_axis, "tickmarkPlacement": "on" }) # And the remaining columns as the graph data if not labels: labels = ["series_%d" % i for i in range(len(data_t)-1)] for label, series in zip(labels, data_t[1:]): H.add_data_set(series, series_type='line', name=label) return hc_plot(H, title, theme)
def plot_bar_chart_from_pandas_dataframe(df): assert list(df[df.columns[0]]) == list( range(1, len(chart_config.OFIG_X_AXIS_CATEGORIES) + 1)), "Dataframe categories are in the wrong order" assert len(df.index) == len( chart_config.OFIG_X_AXIS_CATEGORIES ), "Dataframe does not contain values for every category" question_export_tag = df.columns[0] chart = Highchart() chart.set_dict_options( chart_config.OfigChartOptions.CHART_OPTIONS.to_dict()) for series_name in df.columns[1:]: data = list(df[series_name]) chart.add_data_set( data, series_type="bar", name=series_name, color=chart_config.THISCOVERY_RED, ) return output_to_files(chart, question_export_tag)
def make_chart_asset_allocation(product_map, account): allocations = list( map(functools.partial(get_position_value, product_map, account), account.get_ids())) capital = account.get_stats().tail(1)['day_end_capital'][0] allocations.append({'name': 'Cash', 'value': capital}) total_allocations = sum(map(lambda x: x['value'], allocations)) allocations_percent = list( map( lambda x: { 'name': x['name'], 'y': x['value'] / total_allocations * 100 }, allocations)) chart = Highchart() options = { 'chart': { 'zoomType': 'x' }, 'title': { 'text': 'Asset allocation' }, 'xAxis': { 'type': 'datetime' }, 'yAxis': { 'title': { 'text': 'Daily P/L' } }, 'legend': { 'enabled': False } } chart.set_dict_options(options) chart.add_data_set(allocations_percent, 'pie', 'Asset allocation') return chart
def cat_page(): # return render_template('cat_page.html') url = 'http://catsgalore.me/api/breeds/' r = requests.get(url) breeds = r.json()['breeds'] data = [br['weight'] for br in breeds] weights = [map(float, tuple(b[1:b.find(')')].split(' to '))) for b in data] chart = Highchart() chart.add_data_set(weights, 'scatter', 'Cat Weights') chart.set_dict_options(options) w = BeautifulSoup(open(BASE_URL + "templates/cat_page.html")) c = BeautifulSoup(str(chart.htmlcontent)) scripts = c.find_all(lambda tag: (tag.has_attr('src') and tag.name == 'script') or tag.name == 'link') chart_script = c.find_all( lambda tag: not tag.has_attr('type') and tag.name == 'script')[0] loading = c.div head = w.head div = w.find_all('div', class_='table-wrapper')[0] div.insert(0, loading) div.insert(1, chart_script) for s in scripts: head.append(s) html = w.prettify("utf-8") with open(BASE_URL + "templates/cats.html", "wb") as f: f.write(html) return render_template("cats.html")
def stat(): ''' Pagina con le statistiche nel periodo selezionato ''' # input GET if request.method == 'GET': start_date = request.args.get('start_date', '') stop_date = request.args.get('stop_date', '') # calcolo consumo dati = calcoloConsumo() auto_selezionata = 'Fiesta' ind = (dati['data'] >= datetime.datetime.strptime(start_date,'%Y-%m-%d')) & \ (dati['data'] <= datetime.datetime.strptime(stop_date,'%Y-%m-%d')) & \ (dati['auto'] == auto_selezionata) dati_filt = dati.loc[ind, :].drop( ['id', 'insertdate', 'chilometri_last', 'chilometri_delta'], axis=1).reset_index(drop=True).copy() # Grafico chart = Highchart(width=600, height=500) chart.add_data_set(dati_filt[['data', 'euro al litro']].values.tolist(), series_type='line', name='Prezzo (€/litro)') chart.add_data_set(dati_filt[['data', 'chilometri con un litro']].values.tolist(), series_type='line', name='km con un litro') chart.add_data_set(dati_filt[['data', 'chilometri con un litro CUM' ]].values.tolist(), series_type='line', name='km con un litro avg') chart.set_options('xAxis', {'type': 'datetime', 'gridLineWidth': 1}) # chart.set_options('chart', {'backgroundColor':'transparent'}) chart.set_options('tooltip', {'formatter': 'default_tooltip'}) chart.set_options('title', {'text': 'Statistiche consumo'}) chart.htmlcontent return render_template( 'gas_stat.html', start_date=start_date, stop_date=stop_date, df1=dati_filt.to_html(classes='table', index=False, escape=True).replace( '<th>', '<th style = "background-color: #000099" >'), fig1_head=chart.htmlheader, fig1_body=chart.content)
def piscinaStat(): ''' Pagina con le statistiche degli allenamenti nel periodo selezionato ''' # input GET if request.method == 'GET': start_date = request.args.get('start_date', '') stop_date = request.args.get('stop_date', '') # Scarico i dati da DB: allenamenti compresi tra le date specificate query_text = ("""SELECT strftime('%Y',data) AS anno , strftime('%m',data) AS mese , count(0) AS Nvolte , sum(n_vasche * 25 / lung_vasche) AS somma_vasche , round(avg(n_vasche * 25 / lung_vasche), 1) AS media_vasche , sum(n_vasche * lung_vasche) AS somma_metri , round(avg(n_vasche * lung_vasche), 0) AS media_metri FROM piscina_allenamenti JOIN nome_piscina ON piscina_allenamenti.id_nome_piscina = nome_piscina.id WHERE data >= date('"""+start_date+"""') AND data < date('"""+stop_date+"""') GROUP BY anno , mese""") dati = pd.read_sql_query(query_text, engine) dati['media_metri'] = dati['media_metri'].astype('int') # Grafico chart = Highchart(width = 600, height = 500) dff=[] for i in range(len(dati)): dff.append(str(dati.anno[i])+'/'+str(dati.mese[i])) chart.set_options('xAxis', {'categories': dff, 'gridLineWidth': 1}) chart.set_options('tooltip', {'formatter': 'default_tooltip'}) chart.set_options('title', {'text': 'Statistiche mensili allenamenti'}) # chart.set_options('chart', {'backgroundColor':'transparent'}) chart.add_data_set(dati.Nvolte.values.tolist(), series_type='bar', name='Numero allenamenti') chart.add_data_set(dati.media_metri.values.tolist(), series_type='line', name='Media metri') chart.add_data_set(dati.somma_metri.values.tolist(), series_type='bar', name='Somma metri') chart.htmlcontent; return render_template('piscina_stat.html', start_date=start_date, stop_date=stop_date, df1=dati.to_html(classes='table',index=False,escape=True).replace('<th>','<th style = "background-color: #000099" >'), fig1_head=chart.htmlheader, fig1_body=chart.content)
}, 'subtitle': { 'text': 'Observed in Kansas City, Kansas, USA' }, 'plotOptions': { 'pie': { 'innerSize': 100, 'depth': 45 } } } chart.set_dict_options(options) data = plot chart.add_data_set(data, 'pie', 'Count') chart.save_file("hashtags") elif query == 2: data = q.KCtweets() if data is None: print("Sorry, No Results Are Found!") else: table = PrettyTable() table.field_names = [ "Tweet Id ", "Place", "Create at", "Favorites", "Content" ] for row in data: t_id = row[0] place = row[1]
def create_chart(categories, values, title, filename, charttype, orientation, axisreverse, stack): chart = Highchart() options = { 'chart': { 'type': charttype }, 'title': { 'text': title }, 'xAxis': { 'reversed': axisreverse, 'categories': categories, 'maxPadding': 0.05, 'showLastLabel': True }, 'yAxis': { 'title': { 'text': '#Cases' }, 'stackLabels': { 'enabled': stack, 'style': { 'color': 'black' } }, 'lineWidth': 2 }, 'plotOptions': { 'series': { 'dataLabels': { 'enabled': True, 'style': { 'fontWeight': 'bold', 'color': 'gray' } }, 'stacking': 'normal' } }, 'legend': { 'enabled': True }, 'tooltip': { 'shared': True, 'enabled': True } } chart.set_dict_options(options) print(options) colors = ['#1A5276', '#6E2C00', '#2C3E50'] keys = list(values.keys()) for series in keys: data = values[series] chart.add_data_set(data, charttype, series, marker={'enabled': True}, color=colors[keys.index(series)]) print(filename) chart.save_file(filename)
'created_at'] or 'Sept' in tweet[ 'created_at'] or 'Oct' in tweet[ 'created_at'] or 'Nov' in tweet[ 'created_at'] or 'Dec' in tweet['created_at']: y16 += 1 elif tweet['created_at'][-4:] == '2017': if 'Jan' in tweet['created_at'] or 'Feb' in tweet[ 'created_at'] or 'Mar' in tweet[ 'created_at'] or 'Apr' in tweet[ 'created_at'] or 'May' in tweet[ 'created_at'] or 'Jun' in tweet['created_at']: y17 += 1 elif 'Jul' in tweet['created_at'] or 'Aug' in tweet[ 'created_at'] or 'Sept' in tweet[ 'created_at'] or 'Oct' in tweet[ 'created_at'] or 'Nov' in tweet[ 'created_at'] or 'Dec' in tweet['created_at']: y18 += 1 if (len(tweets)): earlier_tweet_id = sorted(tweet_id_list)[0] else: tweet_count = max_count g_data = [ y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18 ] chart.set_dict_options(options) chart.add_data_set(g_data, 'line', 'PK') chart.save_file('./highcharts')
def plot_scatter(molmap, htmlpath='./', htmlname=None, radius=3): ''' molmap: the object of molmap htmlpath: the figure path, not include the prefix of 'html' htmlname: the name radius: int, defaut:3, the radius of scatter dot ''' title = '2D emmbedding of %s based on %s method' % (molmap.ftype, molmap.method) subtitle = 'number of %s: %s, metric method: %s' % ( molmap.ftype, len(molmap.flist), molmap.metric) name = '%s_%s_%s_%s_%s' % (molmap.ftype, len( molmap.flist), molmap.metric, molmap.method, 'scatter') if not os.path.exists(htmlpath): os.makedirs(htmlpath) if htmlname: name = htmlname + '_' + name filename = os.path.join(htmlpath, name) print_info('generate file: %s' % filename) xy = molmap.embedded.embedding_ colormaps = molmap.extract.colormaps df = pd.DataFrame(xy, columns=['x', 'y']) bitsinfo = molmap.extract.bitsinfo.set_index('IDs') df = df.join(bitsinfo.loc[molmap.flist].reset_index()) df['colors'] = df['Subtypes'].map(colormaps) H = Highchart(width=1000, height=850) H.set_options('chart', {'type': 'scatter', 'zoomType': 'xy'}) H.set_options('title', {'text': title}) H.set_options('subtitle', {'text': subtitle}) H.set_options( 'xAxis', { 'title': { 'enabled': True, 'text': 'X', 'style': { 'fontSize': 20 } }, 'labels': { 'style': { 'fontSize': 20 } }, 'gridLineWidth': 1, 'startOnTick': True, 'endOnTick': True, 'showLastLabel': True }) H.set_options( 'yAxis', { 'title': { 'text': 'Y', 'style': { 'fontSize': 20 } }, 'labels': { 'style': { 'fontSize': 20 } }, 'gridLineWidth': 1, }) # H.set_options('legend', {'layout': 'horizontal','verticalAlign': 'top','align':'right','floating': False, # 'backgroundColor': "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'", # 'borderWidth': 1}) H.set_options( 'legend', { 'align': 'right', 'layout': 'vertical', 'margin': 1, 'verticalAlign': 'top', 'y': 40, 'symbolHeight': 12, 'floating': False, }) H.set_options( 'plotOptions', { 'scatter': { 'marker': { 'radius': radius, 'states': { 'hover': { 'enabled': True, 'lineColor': 'rgb(100,100,100)' } } }, 'states': { 'hover': { 'marker': { 'enabled': False } } }, 'tooltip': { 'headerFormat': '<b>{series.name}</b><br>', 'pointFormat': '{point.IDs}' } }, 'series': { 'turboThreshold': 5000 } }) for subtype, color in colormaps.items(): dfi = df[df['Subtypes'] == subtype] if len(dfi) == 0: continue data = dfi.to_dict('records') H.add_data_set(data, 'scatter', subtype, color=color) H.save_file(filename) print_info('save html file to %s' % filename) return df, H
def hchart_json(): chart = Highchart() data = [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] chart.add_data_set(data, series_type='line', name='Example Series') chart.save_file()
countries = {} for doc in docs: if LANG in doc: lang = doc[LANG] if lang: lang = lang.upper() if lang in langs: langs[lang] += 1 else: langs[lang] = 1 if COUNTRY in doc: country = doc[COUNTRY] if country: if country in countries: countries[country] += 1 else: countries[country] = 1 chart = Highchart() options = {TITLE : {TEXT : 'Results per Language'}} chart.set_dict_options(options) chart.add_data_set(langs.items(), series_type='pie', name='Results') chart.save_file(splitext(argv[2])[0]) chart = Highchart() options = {TITLE : {TEXT : 'Results per Country'}} chart.set_dict_options(options) chart.add_data_set(countries.items(), series_type='pie', name='Results') chart.save_file(splitext(argv[3])[0])
}] options = { 'chart': { 'plotBackgroundColor': None, 'plotBorderWidth': None, 'plotShadow': False }, 'title': { 'text': 'Browser market shares at a specific website, 2014' }, 'tooltip': { 'pointFormat': '{series.name}: <b>{point.percentage:.1f}%</b>' }, } H.set_dict_options(options) H.add_data_set(data, 'pie', 'Browser share', allowPointSelect=True, cursor='pointer', showInLegend=True, dataLabels={ 'enabled': False, 'format': '<b>{point.name}</b>: {point.percentage:.1f} %', 'style': { 'color': "(Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'" } } ) H.htmlcontent
from highcharts import Highchart # A chart is the container that your data will be rendered in, it can (obviously) support multiple data series within it. chart = Highchart() # Adding a series requires at minimum an array of data points. # You can also change the series type, the name, or other series options as kwargs. data = range(1,20) chart.add_data_set(data, series_type='line', name='Example Series') # This will generate and save a .html file at the location you assign chart.save_file()
# -*- coding: utf-8 -*- """ Highcharts Demos Basic line: http://www.highcharts.com/demo/line-basic """ from highcharts import Highchart H = Highchart() data_Tokyo = [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] data_NY = [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] data_Berlin = [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] data_London = [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] H.add_data_set(data_Tokyo, "line", "Tokyo") H.add_data_set(data_NY, "line", "New York") H.add_data_set(data_Berlin, "line", "Berlin") H.add_data_set(data_London, "line", "London") H.set_options("chart", {"zoomType": "x"}) H.set_options( "xAxis", {"categories": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]} ) H.set_options( "yAxis", {"title": {"text": "Temperature (°C)"}, "plotLines": {"value": 0, "width": 1, "color": "#808080"}} ) H.set_options("tooltip", {"valueSuffix": "°C"}) H.set_options("legend", {"layout": "vertical", "align": "right", "verticalAlign": "middle", "borderWidth": 0}) H.set_options("colors", {})
else: top[hashtag] = 1 data[createdAt] = counts top = sorted(top.items(), key=lambda x: x[1], reverse=True) sortedItems = sorted([item for item in data.items()]) series = {} for i in range(min(int(argv[2]), len(top))): hashtag = top[i][0] dataSet = [] for item in sortedItems: if hashtag in item[1]: dataSet.append(item[1][hashtag]) else: dataSet.append(0) series[hashtag] = dataSet categories = [item[0] for item in sortedItems] chart = Highchart() chart.set_options(TITLE, {TEXT : "Top Trending Topics Over Time"}) chart.set_options(XAXIS, {CATEGORIES : categories}) chart.set_options(YAXIS, {TITLE : {TEXT: "Results containing Hashtag"}}) for item in series.items(): chart.add_data_set(item[1], series_type='line', name=item[0]) chart.save_file(splitext(argv[3])[0])
}, 'tooltip': { 'crosshairs': True, 'shared': True, 'pointFormat': '{series.name}: {point.y}°C <br>' } } H.set_dict_options(options) data1 = [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, { 'y': 26.5, 'marker': { 'symbol': 'url(http://www.highcharts.com/demo/gfx/sun.png)' } }, 23.3, 18.3, 13.9, 9.6] data2 = [{'y': 3.9,'marker': { 'symbol': 'url(http://www.highcharts.com/demo/gfx/snow.png)' } }, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] H.add_data_set(data1, 'spline', 'Tokyo', marker={ 'symbol': 'square' }) H.add_data_set(data2, 'spline', 'London', marker={ 'symbol': 'diamond' }) H.htmlcontent
'max': 250, 'opposite': True }], 'tooltip': { 'shared': True }, } data1 = [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] data2 = [[48, 51], [68, 73], [92, 110], [128, 136], [140, 150], [171, 179], [135, 143], [142, 149], [204, 220], [189, 199], [95, 110], [52, 56]] data3 = [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] data4 = [[6, 8], [5.9, 7.6], [9.4, 10.4], [14.1, 15.9], [18.0, 20.1], [21.0, 24.0], [23.2, 25.3], [26.1, 27.8], [23.2, 23.9], [18.0, 21.1], [12.9, 14.0], [7.6, 10.0]] H.set_dict_options(options) H.add_data_set(data1, 'column', 'Rainfall', yAxis = 1, tooltip = { 'pointFormat': '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y:.1f} mm</b> ' }) H.add_data_set(data2, 'errorbar', 'Rainfall error', yAxis = 1, tooltip = { 'pointFormat': '(error range: {point.low}-{point.high} mm)<br/>' }) H.add_data_set(data3, 'spline', 'Temperature', tooltip = { 'pointFormat': '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y:.1f}°C</b> ' }) H.add_data_set(data4, 'errorbar', 'Temperature error', tooltip = { 'pointFormat': '(error range: {point.low}-{point.high}°C)<br/>' }) H.htmlcontent
} } } } }, } H.set_dict_options(options) data1 = [None, None, None, None, None, 6, 11, 32, 110, 235, 369, 640, 1005, 1436, 2063, 3057, 4618, 6444, 9822, 15468, 20434, 24126, 27387, 29459, 31056, 31982, 32040, 31233, 29224, 27342, 26662, 26956, 27912, 28999, 28965, 27826, 25579, 25722, 24826, 24605, 24304, 23464, 23708, 24099, 24357, 24237, 24401, 24344, 23586, 22380, 21004, 17287, 14747, 13076, 12555, 12144, 11009, 10950, 10871, 10824, 10577, 10527, 10475, 10421, 10358, 10295, 10104] data2 = [None, None, None, None, None, None, None, None, None, None, 5, 25, 50, 120, 150, 200, 426, 660, 869, 1060, 1605, 2471, 3322, 4238, 5221, 6129, 7089, 8339, 9399, 10538, 11643, 13092, 14478, 15915, 17385, 19055, 21205, 23044, 25393, 27935, 30062, 32049, 33952, 35804, 37431, 39197, 45000, 43000, 41000, 39000, 37000, 35000, 33000, 31000, 29000, 27000, 25000, 24000, 23000, 22000, 21000, 20000, 19000, 18000, 18000, 17000, 16000] H.add_data_set(data1, 'area', 'USA', ) H.add_data_set(data2, 'area', 'USSR/Russia') H.htmlcontent
'formatter': 'function () {\ return this.value ;\ }' } }, 'tooltip': { 'shared': True, 'valueSuffix': ' millions' }, 'plotOptions': { 'area': { 'stacking': 'normal', 'lineColor': '#666666', 'lineWidth': 1, 'marker': { 'lineWidth': 1, 'lineColor': '#666666' } } } } H.set_dict_options(options) H.add_data_set(data1, 'area', 'Asia') H.add_data_set(data2, 'area', 'Africa') H.add_data_set(data3, 'area', 'Europe') H.add_data_set(data4, 'area', 'America') H.add_data_set(data5, 'area', 'Oceania') H.htmlcontent
drillDataLen = len(data[i]['drilldown']['data']) for j in range(drillDataLen): brightness = 0.2 - (j / drillDataLen) / 5; versionsData.append({ 'name': data[i]['drilldown']['categories'][j], 'y': data[i]['drilldown']['data'][j], 'color': 'Highcharts.Color(' + data[i]['color'] + ').brighten(' + str(brightness) + ').get()' }) H.set_dict_options(options) H.add_data_set(browserData, 'pie', 'Browsers', size='60%', dataLabels={ 'formatter': 'function () { \ return this.y > 5 ? this.point.name : null;\ }', 'color': 'white', 'distance': -30 }) H.add_data_set(versionsData, 'pie', 'Versions', size='80%', innerSize='60%', dataLabels={ 'formatter': "function () {\ return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;\ }" }) H.htmlcontent
data_female = [ 1656154, 1787564, 1981671, 2108575, 2403438, 2366003, 2301402, 2519874, 3360596, 3493473, 3050775, 2759560, 2304444, 2426504, 2568938, 1785638, 1447162, 1005011, 330870, 130632, 21208, ] H.set_dict_options(options) H.add_data_set(data_male, "bar", "Male") H.add_data_set(data_female, "bar", "Female") H.htmlcontent
1. add_data_set(data, series_type="line", name=None, **kwargs) 1. data is the dataset for chart 2. series_type (default: "line") is the type of plot this dataset will be presented 3. name is the variable name of dateset(default: Series X) used in python 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) 2. add_data_from_jsonp(data_src, data_name='json_data', series_type="line", name=None, **kwargs) add dataset from the data_src using jsonp. It is converted to jquery function "$.getJSON" in javascript environment 1. data_src is the url (https) for the dataset 2. data_name is the variable name of dataset. This name is used for javascript environment (not in python) 3. series_type( default: "line") is the type of plot this dataset will be presented 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) """ H.add_data_set(data2,'line') H.add_data_set(data, 'line', marker={ 'states': { 'hover': { 'enabled': True, 'fillColor': 'white', 'lineColor': 'red', 'lineWidth': 2 } } }, events={ 'click': "function (event) { alert(this.name + ' clicked\\n' + 'Alt: ' + event.altKey + '\\n' + \ 'Control: ' + event.ctrlKey + '\\n' + 'Shift: ' + event.shiftKey + '\\n');}"}, dashStyle='ShortDash'
}, 'yAxis': { 'title': { 'text': None } }, 'tooltip': { 'crosshairs': True, 'shared': True, 'valueSuffix': '°C' }, 'legend': { } } H.set_dict_options(options) H.add_data_set(averages, 'line', 'Temperature', zIndex=1, marker={ 'fillColor': 'white', 'lineWidth': 2, 'lineColor': 'Highcharts.getOptions().colors[0]' }) H.add_data_set(ranges, 'arearange', 'Range', lineWidth=0, linkedTo=':previous', color='Highcharts.getOptions().colors[0]', fillOpacity=0.3, zIndex=0 ) H.htmlcontent
[7, 2, 82], [7, 3, 32], [7, 4, 30], [8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84], [9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91] ] H.add_data_set(data, ) H.set_options('chart', { 'type': 'heatmap', 'marginTop': 40, 'marginBottom': 80, 'plotBorderWidth': 1 }) H.set_options('xAxis', { 'categories': ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura'] }) H.set_options('yAxis', { 'categories': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
'legend': { 'layout': 'vertical', 'align': 'right', 'verticalAlign': 'top', 'x': -40, 'y': 80, 'floating': True, 'borderWidth': 1, 'backgroundColor': "((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF')", 'shadow': True }, 'credits': { 'enabled': False }, 'plotOptions': { 'bar': { 'dataLabels': { 'enabled': True } } } } H.set_dict_options(options) H.add_data_set(data1, 'bar', 'Year 1800') H.add_data_set(data2, 'bar', 'Year 1900') H.add_data_set(data3, 'bar', 'Year 2008') H.add_data_set(data4, 'bar', 'Year 2012') H.htmlcontent
}, 'maxPadding': 0.05, 'showLastLabel': True }, 'yAxis': { 'title': { 'text': 'Temperature' }, 'labels': { 'formatter': "function () {\ return this.value + '°';\ }" }, 'lineWidth': 2 }, 'legend': { 'enabled': False }, 'tooltip': { 'headerFormat': '<b>{series.name}</b><br/>', 'pointFormat': '{point.x} km: {point.y}°C' } } chart.set_dict_options(options) data = [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]] chart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) chart.save_file(results)
} }] }, } data =[ [760, 801, 848, 895, 965], [733, 853, 939, 980, 1080], [714, 762, 817, 870, 918], [724, 802, 806, 871, 950], [834, 836, 864, 882, 910] ] data_outline = [[0, 644], [4, 718], [4, 951], [4, 969]] H.set_dict_options(options) H.add_data_set(data, 'boxplot', 'Observations', tooltip = { 'headerFormat': '<em>Experiment No {point.key}</em><br/>'}) H.add_data_set(data_outline, 'scatter', 'Outlier', marker = { 'fillColor': 'white', 'lineWidth': 1, 'lineColor': 'Highcharts.getOptions().colors[0]' }, tooltip = { 'pointFormat': 'Observation: {point.y}' }) H.htmlcontent
def plot_grid(molmap, htmlpath='./', htmlname=None): ''' molmap: the object of molmap htmlpath: the figure path ''' if not os.path.exists(htmlpath): os.makedirs(htmlpath) title = 'Assignment of %s by %s emmbedding result' % (molmap.ftype, molmap.method) subtitle = 'number of %s: %s, metric method: %s' % ( molmap.ftype, len(molmap.flist), molmap.metric) name = '%s_%s_%s_%s_%s' % (molmap.ftype, len( molmap.flist), molmap.metric, molmap.method, 'molmap') if htmlname: name = name = htmlname + '_' + name filename = os.path.join(htmlpath, name) print_info('generate file: %s' % filename) m, n = molmap.fmap_shape colormaps = molmap.extract.colormaps position = np.zeros(molmap.fmap_shape, dtype='O').reshape(m * n, ) position[molmap._S.col_asses] = molmap.flist position = position.reshape(m, n) x = [] for i in range(n): x.extend([i] * m) y = list(range(m)) * n v = position.reshape(m * n, order='f') df = pd.DataFrame(list(zip(x, y, v)), columns=['x', 'y', 'v']) bitsinfo = molmap.extract.bitsinfo subtypedict = bitsinfo.set_index('IDs')['Subtypes'].to_dict() subtypedict.update({0: 'NaN'}) df['Subtypes'] = df.v.map(subtypedict) df['colors'] = df['Subtypes'].map(colormaps) H = Highchart(width=1000, height=850) H.set_options('chart', {'type': 'heatmap', 'zoomType': 'xy'}) H.set_options('title', {'text': title}) H.set_options('subtitle', {'text': subtitle}) # H.set_options('xAxis', {'title': '', # 'min': 0, 'max': molmap.fmap_shape[1]-1, # 'allowDecimals':False, # 'labels':{'style':{'fontSize':20}}}) # H.set_options('yAxis', {'title': '', 'tickPosition': 'inside', # 'min': 0, 'max': molmap.fmap_shape[0]-1, # 'reversed': True, # 'allowDecimals':False, # 'labels':{'style':{'fontSize':20}}}) H.set_options( 'xAxis', { 'title': None, 'min': 0, 'max': molmap.fmap_shape[1], 'startOnTick': False, 'endOnTick': False, 'allowDecimals': False, 'labels': { 'style': { 'fontSize': 20 } } }) H.set_options( 'yAxis', { 'title': { 'text': ' ', 'style': { 'fontSize': 20 } }, 'startOnTick': False, 'endOnTick': False, 'gridLineWidth': 0, 'reversed': True, 'min': 0, 'max': molmap.fmap_shape[0], 'allowDecimals': False, 'labels': { 'style': { 'fontSize': 20 } } }) H.set_options( 'legend', { 'align': 'right', 'layout': 'vertical', 'margin': 1, 'verticalAlign': 'top', 'y': 60, 'symbolHeight': 12, 'floating': False, }) H.set_options('tooltip', { 'headerFormat': '<b>{series.name}</b><br>', 'pointFormat': '{point.v}' }) H.set_options('plotOptions', {'series': {'turboThreshold': 5000}}) for subtype, color in colormaps.items(): dfi = df[df['Subtypes'] == subtype] if len(dfi) == 0: continue H.add_data_set( dfi.to_dict('records'), 'heatmap', name=subtype, color=color, #dataLabels = {'enabled': True, 'color': '#000000'} ) H.save_file(filename) print_info('save html file to %s' % filename) return df, H
'title': { 'text': "Value of Capital" } }, 'tooltip': { 'crosshairs': True, 'shared': True, }, 'legend': { } } H.set_dict_options(options) H.add_data_set(discrete, 'scatter', 'Discrete', color='rgba(223, 83, 83, .5)') H.add_data_set(continuous, 'line', 'Continuous', zIndex=1, marker={ 'fillColor': 'white', 'lineWidth': 2, 'lineColor': 'Highcharts.getOptions().colors[0]' }) html_str = H.htmlcontent.encode('utf-8') html_file = open("chart.html", "w") html_file.write(html_str) html_file.close() # Graph for alpha*beta*A*k.^(alpha)
'categories': ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] }, 'yAxis': { 'allowDecimals': False, 'min': 0, 'title': { 'text': 'Number of fruits' } }, 'tooltip': { 'formatter': "function () {\ return '<b>' + this.x + '</b><br/>' +\ this.series.name + ': ' + this.y + '<br/>' +\ 'Total: ' + this.point.stackTotal;\ }" }, 'plotOptions': { 'column': { 'stacking': 'normal' } } } H.set_dict_options(options) H.add_data_set(data1, 'column', 'John', stack='male') H.add_data_set(data2, 'column', 'Joe', stack='male') H.add_data_set(data3, 'column', 'Jane', stack='female') H.add_data_set(data4, 'column', 'Janet', stack='female') H.htmlcontent
from highcharts import Highchart chart = Highchart() options = { 'chart': { 'type':'bar'}, 'title':{ 'text':'Top 10 Hashtags'}, 'xAxis':{ 'categories':['1','2','3','4','5','6','7','8','9','10']}, 'yAxis':{ 'title':{ 'text':'Number of times mentioned'} }, } data1 #This is an array. make size 10. first means first graoh chart.set_dict_options(options) chart.add_data_set(data1, 'bar', 'Count') chart.save_file('./bar-highcharts')
# -*- coding: utf-8 -*- """ Highcharts Demos Bubble chart: http://www.highcharts.com/demo/bubble """ from highcharts import Highchart H = Highchart(width=850, height=400) options = { 'chart': { 'type': 'bubble', 'zoomType': 'xy' }, 'title': { 'text': 'Highcharts Bubbles' }, } data1 = [[97, 36, 79], [94, 74, 60], [68, 76, 58], [64, 87, 56], [68, 27, 73], [74, 99, 42], [7, 93, 87], [51, 69, 40], [38, 23, 33], [57, 86, 31]] data2 = [[25, 10, 87], [2, 75, 59], [11, 54, 8], [86, 55, 93], [5, 3, 58], [90, 63, 44], [91, 33, 17], [97, 3, 56], [15, 67, 48], [54, 25, 81]] data3 = [[47, 47, 21], [20, 12, 4], [6, 76, 91], [38, 30, 60], [57, 98, 64], [61, 17, 80], [83, 60, 13], [67, 78, 75], [64, 12, 10], [30, 77, 82]] H.set_dict_options(options) H.add_data_set(data1, 'bubble') H.add_data_set(data2, 'bubble') H.add_data_set(data3, 'bubble') H.htmlcontent
}, 'yAxis': { 'allowDecimals': False, 'min': 0, 'title': { 'text': 'Number of fruits' } }, 'tooltip': { 'formatter': "function () {\ return '<b>' + this.x + '</b><br/>' +\ this.series.name + ': ' + this.y + '<br/>' +\ 'Total: ' + this.point.stackTotal;\ }" }, 'plotOptions': { 'column': { 'stacking': 'normal' } } } H.set_dict_options(options) H.add_data_set(data1, 'column', 'John', stack='male' ) H.add_data_set(data2, 'column', 'Joe', stack='male') H.add_data_set(data3, 'column', 'Jane', stack='female') H.add_data_set(data4, 'column', 'Janet', stack='female') H.htmlcontent
}, { 'name': 'E', 'value': 2 }, { 'name': 'F', 'value': 2 }, { 'name': 'G', 'value': 1 }] H.set_dict_options(options) H.add_data_set(data, 'treemap', layoutAlgorithm='squarified', levels = [{ 'level': 1, 'borderWidth': '3px', 'dataLabels': { 'enabled': True, 'align': 'left', 'verticalAlign': 'top', 'color': 'white', 'style': { 'fontWeight': 'bold' } } }, { 'level': 2, 'layoutAlgorithm': 'stripes' }]) H.htmlcontent
'max': 10, 'gridLineWidth': 1 }, 'zAxis': { 'min': 0, 'max': 10, 'showFirstLabel': False }, 'legend': { 'enabled': False }, } data = [[1, 6, 5], [8, 7, 9], [1, 3, 4], [4, 6, 8], [5, 7, 7], [6, 9, 6], [7, 0, 5], [2, 3, 3], [3, 9, 8], [3, 6, 5], [4, 9, 4], [2, 3, 3], [6, 9, 9], [0, 7, 0], [7, 7, 9], [7, 2, 9], [0, 6, 2], [4, 6, 7], [3, 7, 7], [0, 1, 7], [2, 8, 6], [2, 3, 7], [6, 4, 8], [3, 5, 9], [7, 9, 5], [3, 1, 7], [4, 4, 2], [3, 6, 2], [3, 1, 6], [6, 8, 5], [6, 6, 7], [4, 1, 1], [7, 2, 7], [7, 7, 0], [8, 8, 9], [9, 4, 1], [8, 3, 4], [9, 8, 9], [3, 5, 3], [0, 2, 4], [6, 0, 2], [2, 1, 3], [5, 8, 9], [2, 1, 1], [9, 7, 6], [3, 0, 2], [9, 9, 0], [3, 4, 8], [2, 6, 1], [8, 9, 2], [7, 6, 5], [6, 3, 1], [9, 3, 1], [8, 9, 3], [9, 1, 0], [3, 8, 7], [8, 0, 0], [4, 9, 7], [8, 6, 2], [4, 3, 0], [2, 3, 5], [9, 1, 4], [1, 1, 4], [6, 0, 2], [6, 1, 6], [3, 8, 8], [8, 8, 7], [5, 5, 0], [3, 9, 6], [5, 4, 3], [6, 8, 3], [0, 1, 5], [6, 7, 3], [8, 3, 2], [3, 8, 3], [2, 1, 6], [4, 6, 7], [8, 9, 9], [5, 4, 2], [6, 1, 3], [6, 9, 5], [4, 8, 2], [9, 7, 4], [5, 4, 2], [9, 6, 1], [2, 7, 3], [4, 5, 4], [6, 8, 1], [3, 4, 0], [2, 2, 6], [5, 1, 2], [9, 9, 7], [6, 9, 9], [8, 4, 3], [4, 1, 7], [6, 2, 5], [0, 4, 9], [3, 5, 9], [6, 9, 1], [1, 9, 2]] H.set_dict_options(options) H.add_data_set(data, 'scatter', 'Reading', colorByPoint= True) H.add_3d_rotation() # add rotation function H.htmlcontent
}, 'legend': { 'enabled': False }, 'plotOptions': { 'series': { 'borderWidth': 0, 'dataLabels': { 'enabled': True, 'format': '{point.y:.1f}%' } } }, 'tooltip': { 'headerFormat': '<span style="font-size:11px">{series.name}</span><br>', 'pointFormat': '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>' }, } H.set_dict_options(options) H.add_data_set(data, 'column', "Brands", colorByPoint= True) H.add_drilldown_data_set(data_1, 'column', 'Microsoft Internet Explorer', name='Microsoft Internet Explorer' ) H.add_drilldown_data_set(data_2, 'column', 'Chrome', name='Chrome') H.add_drilldown_data_set(data_3, 'column', 'Firefox', name='Firefox') H.add_drilldown_data_set(data_4, 'column', 'Safari', name='Safari') H.add_drilldown_data_set(data_5, 'column', 'Opera', name='Opera') H.htmlcontent
'text': 'Highchart Line' }, 'legend': { 'enabled': True }, 'xAxis': { 'categories': [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ], 'title': { 'text': 'Months of the year' } }, 'yAxis': { 'title': { 'text': 'Number of followers' } }, } data1 = [7, 7, 9, 14, 18, 21, 25, 26, 30, 55, 62, 85] data2 = [11, 17, 22, 25, 56, 76, 91, 102, 150] data3 = [3, 4, 5, 8, 11, 15, 17, 36, 42, 103, 126, 148] chart.set_dict_options(options) chart.add_data_set(data1, 'line', 'User 1') # data, type_of_chart, legend_text chart.add_data_set(data2, 'line', 'User 2') chart.add_data_set(data3, 'line', 'User 3') chart.save_file('./line-highcharts') # write to the file and save
}, 'title': { 'text': "Contents of Highsoft\'s weekly fruit delivery" }, 'subtitle': { 'text': '3D donut in Highcharts' }, 'plotOptions': { 'pie': { 'innerSize': 100, 'depth': 45 } }, } data = [ ['Bananas', 8], ['Kiwi', 3], ['Mixed nuts', 1], ['Oranges', 6], ['Apples', 8], ['Pears', 4], ['Clementines', 4], ['Reddish (bag)', 1], ['Grapes (bunch)', 1] ] H.set_dict_options(options) H.add_data_set(data, 'pie', 'Delivered amount') H.htmlcontent
'text': 'Highchart Bar' }, 'legend': { 'enabled': True }, 'xAxis': { 'categories': ['User 1', 'User 2', 'User 3', 'User 4', 'User 5'], }, 'yAxis': { 'title': { 'text': 'Number of posts (thousands)' } }, } # we can use our own data data1 = [107, 31, 635, 203, 2] data2 = [133, 156, 947, 408, 6] data3 = [973, 914, 4054, 732, 34] data4 = [1052, 954, 4250, 740, 38] chart.set_dict_options(options) # add options to the chart object chart.add_data_set(data1, 'bar', 'Day 1') # data, type_of_chart, legend_text chart.add_data_set(data2, 'bar', 'Day 2') chart.add_data_set(data3, 'bar', 'Day 3') chart.add_data_set(data4, 'bar', 'Day 4') chart.save_file('./highcharts-bar' ) # it will crete an html file. Used to save the html file
}' }, 'maxPadding': 0.05, 'showLastLabel': True }, 'yAxis': { 'title': { 'text': 'Temperature' }, 'labels': { "formatter": u"function () {\ return this.value + '°';\ }" }, 'lineWidth': 2 }, 'legend': { 'enabled': False }, 'tooltip': { 'headerFormat': '<b>{series.name}</b><br/>', 'pointFormat': '{point.x} km: {point.y}°C' } } # then input using set_dict_options method H.set_dict_options(options) data = [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]] H.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) H.htmlcontent
[188.0, 83.6], [198.1, 85.5], [175.3, 90.9], [166.4, 85.9], [190.5, 89.1], [166.4, 75.0], [177.8, 77.7], [179.7, 86.4], [172.7, 90.9], [190.5, 73.6], [185.4, 76.4], [168.9, 69.1], [167.6, 84.5], [175.3, 64.5], [170.2, 69.1], [190.5, 108.6], [177.8, 86.4], [190.5, 80.9], [177.8, 87.7], [184.2, 94.5], [176.5, 80.2], [177.8, 72.0], [180.3, 71.4], [171.4, 72.7], [172.7, 84.1], [172.7, 76.8], [177.8, 63.6], [177.8, 80.9], [182.9, 80.9], [170.2, 85.5], [167.6, 68.6], [175.3, 67.7], [165.1, 66.4], [185.4, 102.3], [181.6, 70.5], [172.7, 95.9], [190.5, 84.1], [179.1, 87.3], [175.3, 71.8], [170.2, 65.9], [193.0, 95.9], [171.4, 91.4], [177.8, 81.8], [177.8, 96.8], [167.6, 69.1], [167.6, 82.7], [180.3, 75.5], [182.9, 79.5], [176.5, 73.6], [186.7, 91.8], [188.0, 84.1], [188.0, 85.9], [177.8, 81.8], [174.0, 82.5], [177.8, 80.5], [171.4, 70.0], [185.4, 81.8], [185.4, 84.1], [188.0, 90.5], [188.0, 91.4], [182.9, 89.1], [176.5, 85.0], [175.3, 69.1], [175.3, 73.6], [188.0, 80.5], [188.0, 82.7], [175.3, 86.4], [170.5, 67.7], [179.1, 92.7], [177.8, 93.6], [175.3, 70.9], [182.9, 75.0], [170.8, 93.2], [188.0, 93.2], [180.3, 77.7], [177.8, 61.4], [185.4, 94.1], [168.9, 75.0], [185.4, 83.6], [180.3, 85.5], [174.0, 73.9], [167.6, 66.8], [182.9, 87.3], [160.0, 72.3], [180.3, 88.6], [167.6, 75.5], [186.7, 101.4], [175.3, 91.1], [175.3, 67.3], [175.9, 77.7], [175.3, 81.8], [179.1, 75.5], [181.6, 84.5], [177.8, 76.6], [182.9, 85.0], [177.8, 102.5], [184.2, 77.3], [179.1, 71.8], [176.5, 87.9], [188.0, 94.3], [174.0, 70.9], [167.6, 64.5], [170.2, 77.3], [167.6, 72.3], [188.0, 87.3], [174.0, 80.0], [176.5, 82.3], [180.3, 73.6], [167.6, 74.1], [188.0, 85.9], [180.3, 73.2], [167.6, 76.3], [183.0, 65.9], [183.0, 90.9], [179.1, 89.1], [170.2, 62.3], [177.8, 82.7], [179.1, 79.1], [190.5, 98.2], [177.8, 84.1], [180.3, 83.2], [180.3, 83.2]] H.set_dict_options(options) H.add_data_set(data1, 'scatter', 'Female', color='rgba(223, 83, 83, .5)') H.add_data_set(data2, 'scatter', 'Male', color='rgba(119, 152, 191, .5)') H.htmlcontent
0.6802, 0.678, 0.6796, 0.6817, 0.6817, 0.6832, 0.6877, 0.6912, 0.6914, 0.7009, 0.7012, 0.701, 0.7005, 0.7076, 0.7087, 0.717, 0.7105, 0.7031, 0.7029, 0.7006, 0.7035, 0.7045, 0.6956, 0.6988, 0.6915, 0.6914, 0.6859, 0.6778, 0.6815, 0.6815, 0.6843, 0.6846, 0.6846, 0.6923, 0.6997, 0.7098, 0.7188, 0.7232, 0.7262, 0.7266, 0.7359, 0.7368, 0.7337, 0.7317, 0.7387, 0.7467, 0.7461, 0.7366, 0.7319, 0.7361, 0.7437, 0.7432, 0.7461, 0.7461, 0.7454, 0.7549, 0.7742, 0.7801, 0.7903, 0.7876, 0.7928, 0.7991, 0.8007, 0.7823, 0.7661, 0.785, 0.7863, 0.7862, 0.7821, 0.7858, 0.7731, 0.7779, 0.7844, 0.7866, 0.7864, 0.7788, 0.7875, 0.7971, 0.8004, 0.7857, 0.7932, 0.7938, 0.7927, 0.7918, 0.7919, 0.7989, 0.7988, 0.7949, 0.7948, 0.7882, 0.7745, 0.771, 0.775, 0.7791, 0.7882, 0.7882, 0.7899, 0.7905, 0.7889, 0.7879, 0.7855, 0.7866, 0.7865, 0.7795, 0.7758, 0.7717, 0.761, 0.7497, 0.7471, 0.7473, 0.7407, 0.7288, 0.7074, 0.6927, 0.7083, 0.7191, 0.719, 0.7153, 0.7156, 0.7158, 0.714, 0.7119, 0.7129, 0.7129, 0.7049, 0.7095 ] H.add_data_set(data, 'area', 'USD to EUR', pointInterval=24 * 3600 * 1000, pointStart=datetime.datetime(2006,1,1)) H.set_options('plotOptions', { 'area': { 'fillColor': { 'linearGradient': { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 1}, 'stops': [ [0, "Highcharts.getOptions().colors[0]"], [1, "Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')"] ]}, 'marker': { 'radius': 2 }, 'lineWidth': 1, 'states': { 'hover': { 'lineWidth': 1